Jump to content
crazycrash

StdoutRead while program is running?

Recommended Posts

crazycrash

Hi

I am trying to read the comandline output of a exe so I can execute certain other tasks depending on the output read. However I can't get the stream during execution / I only get it when the started exe is terminated.

Is there any way to capture the output while the program is running? Just like it is displayed in the cmd window?

Thanks!

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#RequireAdmin

Local $consoleOutputHandle = Run(@ScriptDir & "/test.exe", @ScriptDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
Local $consoleContent
Sleep(5000)
For $i = 1 To 10 ;Miniloop just to test - Messagebox only returns content wen test.exe is terminated
    ;$consoleContent &= StdoutRead($consoleOutputHandle, false, false)
    MsgBox(0,"",StdoutRead($consoleOutputHandle, False, False))
    Sleep(1000)
Next

 

Share this post


Link to post
Share on other sites
Subz

Example

#include <AutoItConstants.au3>

Local $sContent = ""
Local $hPID = Run(@ComSpec & " /c @Echo Off & For /L %x In (1, 1, 1000000) Do Echo %x", "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $sContent = StdoutRead($hPID)
        If @error Then ExitLoop
    If StringStripWS($sContent, 8) = "" Then ContinueLoop
    ConsoleWrite(StringReplace($sContent, @CRLF, "") & @CRLF)
WEnd

 

Share this post


Link to post
Share on other sites
crazycrash

Thanks, it seems it has to do with the exe then. The exe is a cc miner which can be found here: https://github.com/fireice-uk/xmr-stak/releases

Any tips on how to capture the output whilst it is running would be great.

StdoutRead($hPID)

  Only gives me a result with the entire console output if I terminate xmr-stak.exe. During execution it comes back empty. However I need autoit to control it during runtime.

Cheers

Share this post


Link to post
Share on other sites
crazycrash

Found the issue, it was indeed with the exe, the stdout was buffered, changed that and it works just fine. Cheers

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

×