# Function Reference

ConsoleRead

Read in a number of characters from the STDIN stream of the AutoIt script process.

ConsoleRead ( [ count[, peek = false]] )

Parameters

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, STDIN is not connected for the process or other error.

Remarks

ConsoleRead reads from the console standard input stream of the AutoIt script process, which is normally used by console applications to read input from a parent process.
The optional count parameter tells ConsoleRead to read count characters from the stream. If fewer than count characters are available, ConsoleRead returns a string of all the characters that are available. If the function is called with no arguments, ConsoleRead assumes you that you wish to read the maximum number of characters and returns a string of all the characters that are available.
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 ConsoleRead 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 parent process writes something to AutoIt's STDIN stream.
If ConsoleRead is called with a second argument other than zero, ConsoleRead 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" ConsoleRead always returns immediately. Note that the characters are still present on the stream and will be returned on the next read operation.
When called with a first argument of 0 and a second argument that directs the function to "peek", ConsoleRead returns a numeric value of the number of characters that could currently be read from the stream.

Related

ConsoleWrite, ConsoleWriteError, StdoutRead, StderrRead, StdinWrite, Run

Example

;Example to be provided by DaveF