Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

StdOutRead(): is it possible to "Attach" to a lauched CMD.EXE?

$
0
0
Hi.

I'm just wondering, if it might be possible, to open a CMDline Program and to use StdOutRead() / StdErrRead() to "tee" the output to one log file? I want to still be able to interact with the CMDline Program (type in commands, read the StdOut StdErr Output).


Is "tee-ing" possible with StdOutRead() / StdErrRead()

[ autoit ]         
#include <date.au3> #include <Constants.au3> ;  0x2 ($STDOUT_CHILD) = Provide a handle to the child's STDOUT stream ;  0x4 ($STDERR_CHILD) = Provide a handle to the child's STDERR stream $Log = "C:\temp\Std-out-err-read.txt" $hLog = FileOpen($Log, 2 + 8) FileWriteLine($hLog, _NowCalc()) FileWriteLine($hLog, "--------------------------------------------------------------------------------------------") $ExitReason = "" ; when I specify $stdout_child / $stdout_child + $stderr_child, the process dies immediately. ; When I truncate the line, so that it ends " ...,@sw_show)", the cmd box remains open as expected. $pid = Run(@ComSpec & " /k echo this is a first line...", @TempDir, @SW_SHOW, $STDOUT_CHILD + $STDERR_CHILD) While ProcessExists($pid)     $StdOut = StdoutRead($pid)     If @error Then         $ExitReason &= "StdOutRead Error " & @error & @CRLF         ExitLoop     EndIf     If $StdOut <> "" Then FileWrite($hLog, $StdOut)     $StdErr = StderrRead($pid)     If @error Then         $ExitReason &= "StdErrRead Error " & @error & @CRLF         ExitLoop     EndIf     If $StdErr <> "" Then FileWriteLine($hLog, $StdErr) WEnd FileWriteLine($hLog, @CRLF & "--------------------------------------------------------------------------------------------") FileWriteLine($hLog,_NowCalc()) ConsoleWrite($ExitReason & @LF) FileWriteLine($hLog,$ExitReason) FileClose($hLog) Run ("notepad.exe " & $Log)

the CMD box just "blinks" once and disappears. Output to file is this:
2013/02/05 13:54:16
--------------------------------------------------------------------------------------------
this is a first line...

C:\Users\admin\AppData\Local\Temp>
--------------------------------------------------------------------------------------------
2013/02/05 13:54:16



Propably simply WAD?


Regards, Rudi.

Viewing all articles
Browse latest Browse all 12506

Trending Articles