CHttpServer::GetProgramOutput Method  
 
DWORD GetProgramOutput(
  UINT nClientId,  
  LPBYTE lpBuffer,  
  DWORD dwBufferSize  
);

Return a copy of the standard output from the a CGI program executed by the client.

Parameters

nClientId
An unsigned integer which uniquely identifies the client session.
lpBuffer
A buffer that will contain the output from the last program executed by the client. If this parameter is NULL, the method will return the number of bytes of data that was output by the program. Note that this output is not null-terminated.
dwBufferSize
The maximum number of bytes that can be copied into the buffer. If the lpBuffer parameter is NULL, this value should be zero.

Return Value

If the method succeeds, the return value is the number of bytes copied into the specified buffer. If the client ID does not specify a valid client session, the method will return zero. If the client has not executed any programs, the return value will be zero.

Remarks

The GetProgramOutput method is used to obtain a copy of the output generated by a CGI program. To determine the number of bytes of output available to read, call this method with the lpBuffer parameter as NULL and the dwBufferSize parameter with a value of zero. The return value will be the number of bytes of data that was output by the program. It should be noted that for Unicode builds, the buffer is a byte array, not an array of characters, and will not be null-terminated.

This method returns the raw output from the program which may contain a response header block, escape sequences, control characters and embedded nulls. When the application processes the output returned by this method, it should never coerce the buffer pointer to an LPTSTR value because there is no guarantee that the data will be null-terminated. To obtain the output from the program as a null-terminated string, use the GetProgramText method.

This method should only be used within an OnExecute event handler, which occurs after the program has terminated.

Example

LPBYTE lpBuffer = NULL;  // The output buffer
DWORD cbBuffer = 0;      // Number of bytes in the output buffer

// Determine the number of bytes in the output buffer
cbBuffer = pHttpServer->GetProgramOutput(nClientId, NULL, 0);

if (cbBuffer > 0)
{
    // Allocate memory for the buffer
    lpBuffer = new BYTE[cbBuffer + 1];

    // Copy the program output to the buffer
    cbBuffer = pHttpServer->GetProgramOutput(nClientId, lpBuffer, cbBuffer + 1);
}

// Free the memory allocated for the buffer when finished
if (lpBuffer != NULL)
{
    delete lpBuffer;
    lpBuffer = NULL;
    cbBuffer = 0;
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools11.h
Import Library: cshtsv11.lib

See Also

GetProgramExitCode, GetProgramText, OnExecute, RegisterProgram