Jump to content
Sign in to follow this  

Passing output from run to StdOutRead within a while loop

Recommended Posts

I'm trying to monitor the output of a command and am confused by the behaviour of StdOutRead and variables within a while loop. 

Basically there is a command that signals the current status of a local machine as reported by a certain server. I need to know what that status is to trigger other actions. While the status is "online" I want to do one thing, but when the server changes the status of the local machine to "offline" I want to catch that and trigger something else locally.

I've been able to replicate the behaviour using the dir /s command so you guys can run the script and see what I'm seeing.

The first msgbox after the while loop seems to affect whether the run command passes the output to StdOutRead... why is this? I'm thoroughly confused!!

Try un-commenting it and the while will run the same as the previous part...

...and if i'm doing this absolutely completely wrong, let me know! I tried starting from the StdOutRead example file...


#include <Constants.au3>

Local $command = Run(@ComSpec & " /c dir /s msiexec.exe", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $output = stdoutRead($command)
Local $stringloc = StringInStr($output,"windows",2)
msgbox(0,"PRE::string","Go into loop? not if this is a Zero :: " & $stringloc,3)

While $stringloc <> 0
   $command = Run(@ComSpec & " /c dir /s msiexec.exe", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
   $output = stdoutRead($command)
   $stringloc = StringInStr($output,"windows",2)
   msgbox(0,"LOOP::string","stay in loop? not if this is a Zero :: " & $stringloc,3)


Share this post

Link to post
Share on other sites

hello LDan46, welcome to AutoIt and to the forum!

except of the ExitLoop statement before the WEnd, which will exit the loop regardless of the condition, i see nothing wrong with your script. it works fine for me either way.

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...