schilbiz Posted November 1, 2007 Author Posted November 1, 2007 I am new to AutoIt, can you explain exactly what the STDOUT flag value (2) is referring to?The below is from http://www.autoitscript.com/autoit3/files/.../StdoutRead.htmStdoutRead 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).; 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)WendWhile 1 $line = StderrRead($foo) If @error = -1 Then ExitLoop MsgBox(0, "STDERR read:", $line)WendMsgBox(0, "Debug", "Exiting...")
MadBoy Posted November 1, 2007 Posted November 1, 2007 (edited) Lets say you start a "CMD" window. In that window you type Ipconfig /all. That would display some information. How to get that information? You use the Flag 2 option in Run command to gather whatever is displayed by that command. More or less it would look like this: Global $IpconfigOutputOnce $ipconfig_output = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 2) While 1 $ipconfig_data = StdoutRead($ipconfig_output) If @error Then ExitLoop If $ipconfig_data Then $IpconfigOutputOnce &= $ipconfig_data Else Sleep(10) EndIf WEnd $IpconfigOutputOnce = StringStripWS($IpconfigOutputOnce, 7) MsgBox(0, "Test", $IpconfigOutputOnce) Does it makes sense? Of course you can then use StringStripCR, StringStripWS to get a nicer output or even diagnose what it says... Edited November 1, 2007 by MadBoy My little company: Evotec (PL version: Evotec)
schilbiz Posted November 1, 2007 Author Posted November 1, 2007 Lets say you start a "CMD" window. In that window you type Ipconfig /all. That would display some information. How to get that information? You use the Flag 2 option in Run command to gather whatever is displayed by that command. More or less it would look like this: Global $IpconfigOutputOnce $ipconfig_output = Run(@ComSpec & " /c ipconfig /all", '', @SW_HIDE, 2) While 1 $ipconfig_data = StdoutRead($ipconfig_output) If @error Then ExitLoop If $ipconfig_data Then $IpconfigOutputOnce &= $ipconfig_data Else Sleep(10) EndIf WEnd $IpconfigOutputOnce = StringStripWS($IpconfigOutputOnce, 7) MsgBox(0, "Test", $IpconfigOutputOnce) Does it makes sense? Of course you can then use StringStripCR, StringStripWS to get a nicer output or even diagnose what it says... Okay I think so, to reitorate, anytime you want to read info from a cmd line using StdoutRead you will have to use Run to specifiy what you want to output in a MsgBox. Which is determined by what you set in Flag 2? Is that correct?
MadBoy Posted November 1, 2007 Posted November 1, 2007 Okay I think so, to reitorate, anytime you want to read info from a cmd line using StdoutRead you will have to use Run to specifiy what you want to output in a MsgBox. Which is determined by what you set in Flag 2? Is that correct?MsgBox is just an example. You can for example put everything into a file, into an array, read it, check for special chars etc. Just replace the ipconfig /all command with lets say 'help' or 'ping google.com' etc. The flag 2 allows you to read whatever output the command had. There are multiple possibilities you can achieve with this. My little company: Evotec (PL version: Evotec)
schilbiz Posted November 1, 2007 Author Posted November 1, 2007 MsgBox is just an example. You can for example put everything into a file, into an array, read it, check for special chars etc. Just replace the ipconfig /all command with lets say 'help' or 'ping google.com' etc. The flag 2 allows you to read whatever output the command had. There are multiple possibilities you can achieve with this.Nice that sounds like a potentially handy tool. Thanks for the info.
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