Read from the STDIN stream of the AutoIt script process.
ConsoleRead ( [peek = False [, binary = False]] )
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). |
Success: | the data read. @extended contains the number of bytes read. |
Failure: | sets the @error flag to non-zero if EOF is reached, STDIN is not connected for the process or other error. |
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.
ConsoleRead() 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.
ConsoleWrite, ConsoleWriteError, Run
#include <MsgBoxConstants.au3>
#cs
Compile this script to "ConsoleRead.exe".
Open a command prompt to the directory where ConsoleRead.exe resides.
Type the following on the command line:
echo Hello! | ConsoleRead.exe
When invoked in a console window, the above command echos the text "Hello!"
but instead of displaying it, the | tells the console to pipe it to the STDIN stream
of the ConsoleRead.exe process.
#ce
Example()
Func Example()
If Not @Compiled Then
MsgBox($MB_SYSTEMMODAL, "", "This script must be compiled in order to run the example.")
Exit
EndIf
Local $sOutput
While True
$sOutput &= ConsoleRead()
If @error Then ExitLoop
Sleep(25)
WEnd
MsgBox($MB_SYSTEMMODAL, "", "Received: " & @CRLF & @CRLF & $sOutput)
EndFunc ;==>Example