cookiemonster Posted March 13, 2014 Share Posted March 13, 2014 Hey, im trying to read the output from a cmd window so I can create an if/else statement for if it errors or is successful, but at the moment I can get the output. Also oddly enough when I put ', $STDERR_CHILD + $STDOUT_CHILD' at the end of the first line, it stops the cmd window from staying open when the switch is set to /c which should keep the window open when its finished, if you remove ', $STDERR_CHILD + $STDOUT_CHILD' then the window stays open like it should Anyone got any ideas? Local $iPID = RunWait(@ComSpec & " /c " & 'adb tcpip 5555', @SystemDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = "" $sOutput = StdoutRead($iPID) MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput) $sOutput = StderrRead($iPID) MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput) Link to comment Share on other sites More sharing options...
Developers Solution Jos Posted March 13, 2014 Developers Solution Share Posted March 13, 2014 You need to use Run() in stead of RunWait as the 4th parameter for RunWait() is: opt_flag [optional] Controls various options related to how the parent and child process interact. 0x10000 ($RUN_CREATE_NEW_CONSOLE) = The child console process should be created with its own window instead of using the parents window. This flag is only useful when the parent is compiled as a Console application. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
cookiemonster Posted March 13, 2014 Author Share Posted March 13, 2014 Ok ive changed that and it now returns the error from the command window if I use the following: Local $iPID = Run(@ComSpec & " /c " & 'adb tcpip 5555', @SystemDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = "" $sOutput = StdoutRead($iPID) MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput) $sOutput = StderrRead($iPID) MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput) Now I dont need the StdoutRead, I only need StderrRead, but if I remove StdoubtRead msgbog then StderrRead msgbox stops showing the reply Local $iPID = Run(@ComSpec & " /c " & 'adb tcpip 5555', @SystemDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = "" $sOutput = StderrRead($iPID) MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput) Any idea why? Link to comment Share on other sites More sharing options...
cookiemonster Posted March 13, 2014 Author Share Posted March 13, 2014 Wasnt giving it enough time, I put a sleep in before reading the output and that sorted it Local $iPID = Run(@ComSpec & " /k " & 'adb tcpip 5555', @SystemDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = "" Sleep (500) $sOutput = StderrRead($iPID) MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput) Link to comment Share on other sites More sharing options...
cookiemonster Posted March 13, 2014 Author Share Posted March 13, 2014 How can I make it wait for the cmd window to finish before moving to the msgbox without using a sleep? as one command im using replys with the error or success within a second, however another takes upto 25 seconds, I dont want it to sleep for 25 seconds before displaying the message box if it is succesfull.... Link to comment Share on other sites More sharing options...
Gianni Posted March 13, 2014 Share Posted March 13, 2014 (edited) maybe like this? #include <Constants.au3> #include <MsgBoxConstants.au3> Local $iPID = Run(@ComSpec & " /c " & 'adb tcpip 5555', @SystemDir, @SW_HIDE, $STDERR_MERGED) ; $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = "" Do $sOutput &= StdoutRead($iPID) Until @error MsgBox($MB_SYSTEMMODAL, "Stderr or stdout Read:", $sOutput) Edited March 13, 2014 by PincoPanco Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
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