cryton2707 Posted November 6, 2005 Posted November 6, 2005 Hi all,Im woundering if anyone has done this.. but basically I want to capture the out put to a console.. and pull it into an auto it script.simple example would be if you Run(@systemdir &"\cmd.exe /k dir c:\ /w")this basically calls dir in a window.I could redicret the out put fro mthe command to a file and then read the file from autoit but would much rather prefer to grab the output directly from the window.Anyone know how to do this?Any help most appreciated.. Welcome to the internet :) where men are men! Women are men! and 16 year old women are FBI agents!
MHz Posted November 7, 2005 Posted November 7, 2005 (edited) It is a feature that is only in the latest beta version of AutoIt here. Look in the beta helpfile for the new parameters for Run() that enable stdout. You will then use the STD* functions to help collect the streams from the running console.Example for StdOutRead from helpfile; 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 = -1 Then ExitLoop MsgBox(0, "STDOUT read:", $line) Wend While 1 $line = StderrRead($foo) If @error = -1 Then ExitLoop MsgBox(0, "STDERR read:", $line) Wend MsgBox(0, "Debug", "Exiting...") Edited November 7, 2005 by MHz
themax90 Posted November 7, 2005 Posted November 7, 2005 (edited) Look in the help file and search the forum for:StdinWriteStdOutReadStderrReadIt's in the new beta 3.1.1.86.Download beta at:http://www.autoitscript.com/autoit3/files/...-beta-Setup.exeStdinWriteexpandcollapse popupStdinWrite -------------------------------------------------------------------------------- Write a number of characters to the STDIN stream of a previously run child process. StdinWrite ( process_id[, string] ) Parameters process_id The process ID of a child process, as returned by a previous call to Run. string String of characters to write. Return Value Success: Returns the number of characters written. Failure: Sets @error to -1 if STDIN was not redirected for the process or other error. Remarks StdinWrite writes to the console standard input stream for a child process, which is normally used by console applications to read input from the user i.e. from the keyboard. During the call to Run for the child process you wish to write to the STD I/O parameter must have included the value of $Stdin_Child for this function to work properly. The optional second parameter is the string that you wish StdinWrite to write to the stream. If the function is called with no second argument, StdinWrite closes the stream and invalidates it for further writing. The stream is a first-in first-out buffer with an arbitrary limited size; if at any time when this function is called (unless it's being called to close the stream) there is no room for more characters to be written to the stream, the StdinWrite function will block (pause) and not return until the child process closes the stream or reads enough characters from the stream to permit the write procedure to complete. This means that the AutoIt process will be halted, and there will be no processing of hotkeys, GUI messages, etc. until the child process reads from the STDIN stream. Streams of child processes run with RunAsSet are cannot be written to this time. Related StdoutRead, StderrRead, Run Example ; Demonstrates the use of StdinWrite() #include <Constants.au3> $foo = Run("sort.exe", @SystemDir, @SW_HIDE, $STDIN_CHILD + $STDOUT_CHILD) ; Write string to be sorted to child sort.exe's STDIN StdinWrite($foo, "rat" & @CRLF & "cat" & @CRLF & "bat" & @CRLF) ; Calling with no 2nd arg closes stream StdinWrite($foo) ; Read from child's STDOUT and show MsgBox(0, "Debug", StdoutRead($foo))StdoutReadexpandcollapse popupStdoutRead -------------------------------------------------------------------------------- Read in a number of characters from the STDOUT stream of a previously run child process. StdoutRead ( 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 -1 if EOF is reached, STDOUT was not redirected for the process or other error. Remarks StdoutRead 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 STDOUT flag value (2) for this function to work properly (see the Run function). The optional second parameter tells StdoutRead to read count characters from the stream. If fewer than count characters are available, StdoutRead 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, StdoutRead 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 StdoutRead 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 STDOUT stream. If StdoutRead is called with a third argument other than zero, StdoutRead 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" StdoutRead 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", StdoutRead 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 StderrRead, 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 = -1 Then ExitLoop MsgBox(0, "STDOUT read:", $line) Wend While 1 $line = StderrRead($foo) If @error = -1 Then ExitLoop MsgBox(0, "STDERR read:", $line) Wend MsgBox(0, "Debug", "Exiting...")StderrReadexpandcollapse popupStderrRead -------------------------------------------------------------------------------- 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 -1 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 = -1 Then ExitLoop MsgBox(0, "STDOUT read:", $line) Wend While 1 $line = StderrRead($foo) If @error = -1 Then ExitLoop MsgBox(0, "STDERR read:", $line) Wend MsgBox(0, "Debug", "Exiting...")Topics:StdinWrite Bug? http://www.autoitscript.com/forum/index.php?showtopic=16927Reading Stdinhttp://www.autoitscript.com/forum/index.php?showtopic=13315 Edited November 7, 2005 by AutoIt Smith
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now