Jump to content
LoWang

make a process flush it's STDOUT

Recommended Posts

LoWang

Hello, I am trying to get stdout of a process launched by run() function, but stdoutread in a loop does not seem to be getting anything UNTIL I quit that process! Then it gets all the output. How do I make it flush or whatever so it is readable? If I run the process normally I can see it's output in a command line, but don't know how to catch it in realtime...

$pid=run("C:\myproc.exe",@SystemDir, @SW_HIDE, $STDERR_MERGED + $STDOUT_CHILD)

ConsoleWrite("pid:"&$pid&@CRLF)
While @error <> -1
 $sline = StdoutRead($pid)
 If @error Then ExitLoop
 if $sline = "" Then ContinueLoop
 consolewrite($sline&@CRLF)
 Sleep(100)
Wend
StdioClose($pid)

Share this post


Link to post
Share on other sites
LoWang

hmm so it seems it somehow works but only after certain interval. It looks like a few minutes before it gets flushed and stdoutread gets the data... so maybe this will be enough for me... :oops:

Edited by LoWang

Share this post


Link to post
Share on other sites
LoWang

hm but it seems I cannot rely on it and in some cases it is not few minutes but much longer (or never?...). So anybody have and idea please?

Share this post


Link to post
Share on other sites
LxP

I'm reviving this old topic because it's the top Google result for "AutoIt flush STDOUT," and no other similar threads seem to give a solution.

I'm experiencing the same problem: the only way I can detect a specific action is to match certain STDOUT output by a console executable, but StdoutRead() doesn't see any output until after the process terminates.

My belief is that the executable is flushing STDOUT per line when run "interactively," but not flushing at all when AutoIt is connecting to the process (presumably in a manner that the console executable sees as "non-interactive").

A possible solution to this problem might be to invoke the executable in a way that makes it believe it's being run interactively.  Is anyone aware of a way to do this with AutoIt?  Is this sort of thing even possible under Windows?

I know nothing about the internal workings of AutoIt (or Windows IPC), but is it possible that the implementation of StdoutRead() can be changed to manually flush STDOUT before it's read?

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

×