Jump to content
Sign in to follow this  
cookiemonster

StdoutRead / StderrRead for RunWait(@ComSpec

Recommended Posts

cookiemonster

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)

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
cookiemonster

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?

Share this post


Link to post
Share on other sites
cookiemonster

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)

Share this post


Link to post
Share on other sites
cookiemonster

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....

Share this post


Link to post
Share on other sites
Chimp

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 by PincoPanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×