Function Reference


StderrRead

Reads from the STDERR stream of a previously run child process.

StderrRead ( process_id [, peek = False [, binary = False]] )

Parameters

process_id The process ID of a child process, as returned by a previous call to Run.
peek [optional] If True the function does not remove the read characters from the stream.
binary [optional] If True the function reads the data as binary instead of text (default is text).

Return Value

Success: the data read. @extended contains the number of bytes read.
Failure: sets the @error flag to non-zero if EOF is reached, STDERR was not redirected for the process or other error.

Remarks

StderrRead() reads from the console standard output stream of a child process, which is normally used by console applications to write to the screen. During the call to Run() for the child process you wish to read from the STD I/O parameter must have included the value of $STDERR_CHILD (4) for this function to work properly (see the Run() function).
StderrRead() does not block, it will return immediately. In order to get all data, it must be called in a loop.
Peeking on the stream does not remove the data from the buffer, however, it does return the available data as normal.
By default, data is returned in text format. By using the binary option, the data will be returned in binary format.

Related

StdoutRead, StdinWrite, StdioClose, Run, RunAs

Example

#include <Constants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $iPID = Run(@ComSpec & " /c DIR Example.au3", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Local $sOutput = ""
    While 1
        $sOutput = StdoutRead($iPID)
        If @error Then ; Exit the loop if the process closes or StdoutRead returns an error.
            ExitLoop
        EndIf
        MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)
    WEnd

    While 1
        $sOutput = StderrRead($iPID)
        If @error Then ; Exit the loop if the process closes or StderrRead returns an error.
            ExitLoop
        EndIf
        MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput)
    WEnd
EndFunc   ;==>Example