Sign in to follow this  
Followers 0
LDan416

Passing output from run to StdOutRead within a while loop

2 posts in this topic

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

Thanks!

#include <Constants.au3>

Local $command = Run(@ComSpec & " /c dir /s msiexec.exe", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
msgbox(0,"PRE::dir",$command,2)
Local $output = stdoutRead($command)
msgbox(0,"PRE::out",$output,2)
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)
   ;msgbox(0,"LOOP::dir",$command,2)
   $output = stdoutRead($command)
   msgbox(0,"LOOP::out",$output,2)
   $stringloc = StringInStr($output,"windows",2)
   msgbox(0,"LOOP::string","stay in loop? not if this is a Zero :: " & $stringloc,3)
   ExitLoop
 WEnd

exit

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  
Followers 0