# Function Reference

StderrRead

Read in a number of characters from the STDERR stream of a previously run child process.

StderrRead ( process_id[, count[, peek = false]] )

Parameters

process_id | The process ID of a child process, as returned by a previous call to Run.
count | The number of characters to read.
peek | If true the function does not remove the read characters from the stream.

Return Value

Success: | Returns a string of the characters read.
Failure: | Sets @error to non-zero if EOF is reached, STDERR was not redirected for the process or other error.

Remarks

StderrRead reads from the console standard error stream of a child process, which is normally used by console applications to write errors 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 STDERR flag value (4) for this function to work properly (see the Run function).
The optional second parameter tells StderrRead to read count characters from the stream. If fewer than count characters are available, StderrRead returns a string of all the characters that are available at that time. If the function is called with no second argument or a second argument of less than zero, StderrRead assumes you that you wish to read the maximum number of characters and returns a string of all the characters that are available (up to 64kb in a single read).
If at any time when this function is called (except for "peeking" as described below) there are no characters to be read from the stream, the StderrRead function will block (pause) and not return until there are characters to be read from the stream. This means that the AutoIt process will be halted, and there will be no processing of hotkeys, GUI messages, etc. until the child process writes something to the STDERR stream.
If StderrRead is called with a third argument other than zero, StderrRead will "peek at" the stream rather than actually reading from it, and return the characters that could be read from the stream. When run as a "peek" StderrRead always returns immediately. Note that any characters are still present on the stream after a peek and will be returned on the next read operation.
When called with a second argument of 0 and a third argument that directs the function to "peek", StderrRead returns a numeric value of the number of characters that could currently be read from the stream.
Streams of child processes run with RunAsSet are cannot be read from at this time.

Related

StdoutRead, StdinWrite, Run

Example

; Demonstrates StdoutRead()
#include <Constants.au3>
$foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
$line = StdoutRead($foo)
If @error Then ExitLoop
MsgBox(0, "STDOUT read:", $line)
Wend
While 1
$line = StderrRead($foo)
If @error Then ExitLoop
MsgBox(0, "STDERR read:", $line)
Wend
MsgBox(0, "Debug", "Exiting...")