new2this Posted January 22, 2008 Share Posted January 22, 2008 I have a script that runs several different command line executables where I capture the response with this loop: $commandline = "command exe with arguments" $foo = Run($commandline, Working Dir, @sw_hide,$STDERR_CHILD + $STDOUT_CHILD) While 1 ___$line = StdoutRead($foo) ___If @error Then ExitLoop ___MsgBox(0,"",$line) Wend While 1 ___$line = StderrRead($foo) ___If @error Then ExitLoop ___MsgBox(0,"","Unable to run exe") Wend The problem with this is that the output of my command is 200+ lines and I would like to capture the output line by line. It appears that it gives it to me in multiple lines, delimited only when the maximum character count for that line has been reached. I have tried a StringSplit(StdoutRead($foo),@LF) which gives me close to what I need, but since the split occurs after the StdoutRead, the array is not populated with EVERY line being a separate entry. The only way that I have been able to successfully capture the output is to pipe it to a text file, then read it back in line by line. Is there another way to capture the command line return value that will allow me to obtain it line by line or delimited with @LF? Any help would be greatly appreciated. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 22, 2008 Developers Share Posted January 22, 2008 (edited) Something line this ? #include<constants.au3> Global $StdOutTot, $StdErrTot $commandline = "Dir * /S" $foo = Run(@ComSpec & " /c " & $commandline, @WorkingDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $StdOutTot &= StdoutRead($foo) If @error Then ExitLoop ;~ MsgBox(0, "", $line) WEnd While 1 $StdErrTot &= StderrRead($foo) If @error Then ExitLoop ;~ MsgBox(0, "", "Unable to run exe") WEnd $StdOutRecs = StringSplit($StdOutTot, @CRLF, 1) $StdErrRecs = StringSplit($StdErrTot, @CRLF, 1) ConsoleWrite(" StdOutLines=" & $StdOutRecs[0] & @CRLF) ConsoleWrite(" StdErrLines=" & $StdErrRecs[0] & @CRLF) Edited January 22, 2008 by 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...
new2this Posted January 22, 2008 Author Share Posted January 22, 2008 Brilliant...! I never knew that you could "&=". It seems that this is the key. You have made life so much easier for me, thanks! 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