Jump to content

How to capture StdoutRead value


 Share

Recommended Posts

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

  • Developers

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...