Jump to content
Sign in to follow this  
happyuser

Use of $STDOUT_CHILD (SOLVED)

Recommended Posts

happyuser

Hello

I have tried AUTOIT to implement an interface for users of a computing task. I would like to include a progress bar into the interface but I need communicating with the .exe child of my GUI.

I have tried to make it write some char to STDOUT and to get them back.

I get nothing when reading $STDOUT_CHID. Could you give me some advice or a sample code?

Here is what I have programmed :

Run("myexe.exe","",@SW_HIDE,2)

$m=""

while stringlen($m)<5

$m=$m&FileRead($stdout_child,1)

WEnd

msgbox(0,"",$m)

My programm seems to never end.

Thank you in advance

Edited by happyuser

Share this post


Link to post
Share on other sites
Valuater

$m=""

while stringlen($m)<5

***************

will run forever

you want to read or write???

example from help

; Demonstrates StdoutRead()
#include <Constants.au3>

Local $foo = Run(@ComSpec & " /c dir foo.bar", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

MsgBox(0, "Debug", "Exiting...")

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
happyuser

Thanks Valuater, I have stepped forward a great step. I now know the syntax of StdOutRead. Nevertheless, I cannot realize what I need i.e. a progress bar that will indicate the percentage an external task has achieved. Let me explain :

I launch an external task with function "run". I then poll stdout to catch the output of my task (numbers progressing from 1 to 20 every 1/10th of second).

I expected that the progress bar included in GUI would follow the progress of the external task. I choose option peek for StdOutRead not to wait for a char in the buffer. Nothing happen until the task is over. At that moment, the bar shows a positive value and the state no longer evoluates.

Here is my code :

Local $Button_1, $msg

GUICreate("My GUI Button")

$Button_1 = GUICtrlCreateButton("Run .EXE", 10, 30, 100)

$prg=GUICtrlCreateProgress(10,60,200,20)

$in=GUICtrlCreateInput("",10,90,200,20)

GUISetState()

$tst=0

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $Button_1

$tst=Run('test.exe','',0,$STDOUT_CHILD)

EndSelect

if $tst<>0 Then

$line = StdoutRead($tst,-1,1)

$n=stringlen($line)

GUICtrlSetData($prg,$n)

GUICtrlSetData($in,$line)

EndIf

WEnd

EndFunc

Where do I get stuck during execution of the external task?

Thank you for advices.

Share this post


Link to post
Share on other sites
Valuater

Where do I get stuck during execution of the external task?

Thank you for advices.

AFAIK... that's the way it is, it reports back at the "end" of the process

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
happyuser

If I understand well what is said in help file, it should work the way I need, the external task running while its output is monitored by the parent script. Let's read the article relative to StdOutRead :

"If StdoutRead is called with a third argument other than zero, StdoutRead will "peek at" the stream rather than actually reading from it, and return the characters that could be read from the stream. When run as a "peek" StdoutRead always returns immediately. Note that any characters are still present on the stream after a peek and will be returned on the next read operation."

While waiting for a message from my window, the script should query for output from child allowing to check the progress through periodic output.

Would you agree or what did I miss?

Share this post


Link to post
Share on other sites
happyuser

Tank you I check all those ref

A day later..

I found that data coming from console output if buffered and delivered by StdoutRead when buffer is full. My task was not enough verbose to fill the buffer and nothing happened til end of task. I have formatted every output of the task in order to fill the buffer (255 char). Now every output triggers the read and the progress bar runs smoothly from 0% to 100%.

Edited by happyuser

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.