Sign in to follow this  
Followers 0
squadjot

How to read from a CMD prompt window in process?

4 posts in this topic

#1 ·  Posted (edited)

Hi great program.. i have a little problem tho.

I would like to read the contents of CMD-prompt-window while its processing

i tried following to get an "realtime" output from the window, but it seems like the app freezes until the ping test is fully done..

#include <Constants.au3>
Local $file = FileOpen("test.txt", 1)
Local $foo = Run('ping cola.jp', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Local $line
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    $message = ""
    $message = $message & $line & @LF
    FileWriteLine($file, $line)
    sleep(200)
Wend

This does not work, the file gets written only at the end / when the CMDprompt is fully done

Does anyone know a trick how to do it without being stuck while the CMD Prompt is processing??

ps. seems like this postmight be about similar problem

Thanks!

Edited by squadjot

Share this post


Link to post
Share on other sites



Can't duplicate your symptoms. What makes you think it "freezes", and what makes you think the file is only written to at the end? How are you checking that?

You should be closing the open file with FileClose($file). That is not causing any symptoms because all open handles are closed when the script exits, but is good practice.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Can't duplicate your symptoms. What makes you think it "freezes", and what makes you think the file is only written to at the end? How are you checking that?

You should be closing the open file with FileClose($file). That is not causing any symptoms because all open handles are closed when the script exits, but is good practice.

;)

Well i had a 3rd part app reading on that output file ever 20 ms..

Nevermind i found another way to do all this.

Share this post


Link to post
Share on other sites

Well i had a 3rd part app reading on that output file ever 20 ms..

Because you did not Open/Write/Close the file each time you added a line it is being held open for write the whole time. The data is going to the file in the mean time, but can't be read until the file gets closed.

If you don't open a file before hand, and simply put the string path in $file, then each you call FileWriteLine() AutoIt will open/write/close the file. That might work better for you if intermediate reads are required.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

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