Jump to content

stdoutread problems


Ixel
 Share

Recommended Posts

Let me apologize in advance for my poor AutoIt skills. I am running a command in a DOS window and trying to get AutoIT to stream the output to a window while the process is still running. Here is my code (just test code):

$foo = Run(@ComSpec & " /c imagex /scroll /apply e:\jmuxpai\winxp091606.wim 1 c:","","",2)
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    msgbox(0,"test",StdoutRead($foo))
    sleep(100)      
Wend
msgbox(0,"test","engaging 2nd loop")
While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

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

The command shows on the console...

Progress 1%

Progress 2%

Progress 3%

etc.

Basically I'm trying to get the progress percent to show in a window (was planning on using splashtext or progresson); however, I can't get the a read on the progress until imagex completes. By then the progress is 100%. This also does not work redirecting output to a file (i.e. imagex > imagex.txt). So it seems like stdoutread does not show anything until the command completes. Is there a way around this?

Link to comment
Share on other sites

First off you have "While 1" two times so script wont get to your second script until you stop the first, i would love to explain how but i dont have the time right now, but i can answer it inn the morning.

Dunno if im totaly wrong now, i might be though since im on my way to town :lmao:

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

Basically I'm trying to get the progress percent to show in a window (was planning on using splashtext or progresson); however, I can't get the a read on the progress until imagex completes. By then the progress is 100%. This also does not work redirecting output to a file (i.e. imagex > imagex.txt). So it seems like stdoutread does not show anything until the command completes. Is there a way around this?

Try to add the second parameter to StdoutRead(). It's the number of characters to read at once. So in your case:

$line = StdoutRead($foo,13) ;

From help file:

StdoutRead

The optional second parameter tells StdoutRead to read count characters from the stream. If fewer than count characters are available, StdoutRead returns a string of all the characters that are available at that time. If the function is called with no second argument or a second argument of less than zero, StdoutRead assumes you that you wish to read the maximum number of characters and returns a string of all the characters that are available (up to 64kb in a single read).

Not sure if that helps (i cannot test at the moment), but it's worth a try...

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

try this:

$foo = Run(@ComSpec & " /c imagex /scroll /apply e:\jmuxpai\winxp091606.wim 1 c:","","",2)
While 1
    $line = StdoutRead($foo)
    If (@error) = 1 Then ExitLoop
         msgbox(0,"test",StdoutRead($foo))
         sleep(100)   
         msgbox(0,"test","engaging 2nd loop")
    EndIf
    
    $line = StderrRead($foo)
    If (@error) = 1 Then ExitLoop
         MsgBox(0, "STDERR read:", $line)
    EndIf
Wend

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

Just edit "(@error) = 1" to what ever error value you are looking for.

Edited by jokke
UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

try this:

$foo = Run(@ComSpec & " /c imagex /scroll /apply e:\jmuxpai\winxp091606.wim 1 c:","","",2)
While 1
    $line = StdoutRead($foo)
    If (@error) = 1 Then ExitLoop
         msgbox(0,"test",StdoutRead($foo))
         sleep(100)   
         msgbox(0,"test","engaging 2nd loop")
    EndIf
    
    $line = StderrRead($foo)
    If (@error) = 1 Then ExitLoop
         MsgBox(0, "STDERR read:", $line)
    EndIf
Wend

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

Just edit "(@error) = 1" to what ever error value you are looking for.

erm.... did you ever try to run your "code"???

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

No i didn't.

As stated earlier im on my way to town, and i might have drinken 1 or 2 many drinks :lmao:

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.
Link to comment
Share on other sites

@jokke and /dev/null

Thanks for your help on this. I don't see the issue being the use of two while statements. The first msgbox does not even show until imagex completes. I am positive about this--hence the reason I want to see a message when the 2nd loop was engaged. I tried using the second parameter on stdoutread (set it to 10)--it still won't show anything until imagex completes. jokke, I am not sure what you were trying to show me in your sample script as it contains a few errors (i.e. endif statements). Again, I apologize if I appear totally lost on this.

Thanks,

Ixel

Link to comment
Share on other sites

basically it works, see code below. So it could be a "problem" with your application...

Runner.bat

@echo off
echo Progress 1%
sleep 2
echo Progress 2%
sleep 2
echo Progress 3%
sleep 2
echo Progress 4%
sleep 2
echo Progress 5%
sleep 2
echo Progress 6%
sleep 2
echo Progress 7%
sleep 2
echo Progress 8%
sleep 2
echo Progress 9%
sleep 2
echo Progress 10%

sleep.exe is part of the Ressource Kit Tools!!

AU3 Script

$foo = Run(@ComSpec & " /c c:\temp\runner.bat","C:\temp\",@SW_HIDE,2)
While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    msgbox(0,"test",$line,1)
    sleep(100)   
Wend
msgbox(0,"test","engaging 2nd loop")

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Do it this way to get ALL the output:

$foo = Run(@ComSpec & " /c c:\temp\runner.bat", "C:\temp\", @SW_HIDE, 2+4) ; handles to STDOUT and STDERR
$OutLine = ""
$ErrLine = ""
While 1
    $OutLine &= StdOutRead($foo)
    If @error Then ExitLoop
    $ErrLine &= StdErrRead($foo)
    If @error Then ExitLoop
    sleep(10)   
Wend
msgbox(0,"Results","STDOUT: " & $OutLine & @CRLF & "ERROUT: " & $ErrLine)

:lmao:

Edited by PsaltyDS
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
Link to comment
Share on other sites

@/dev/null

I think I agree with you that there is something different about the program I am running and therefore why I am having problems with the output.

@psaltyds

Yes that code does work and shows everything, but I would need the msgbox (or splashtexton or progressset) to be in the while loop and updated as output in the DOS window is updated. That's what I can't get working.

Caio,

Ixel

Link to comment
Share on other sites

@/dev/null

I think I agree with you that there is something different about the program I am running and therefore why I am having problems with the output.

Maybe your prorgam writes to STDERR and not STDOUT. StdoutRead() will then block until the program quits. Can you redirect the output of your program with > at the DOS prompt? If so, it writes to STDOUT. If not, it writes to STDERR.

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Maybe your prorgam writes to STDERR and not STDOUT. StdoutRead() will then block until the program quits. Can you redirect the output of your program with > at the DOS prompt? If so, it writes to STDOUT. If not, it writes to STDERR.

Cheers

Kurt

I can but the file remains blank until imagex completes. There must be some way to capture real-time DOS output from this program and throw it back to a GUI.

Edited by Ixel
Link to comment
Share on other sites

I can but the file remains blank until imagex completes. There must be some way to capture real-time DOS output from this program and throw it back to a GUI.

BTW: Are you running your script on Windows Vista (imagex seems to be a new tool for Vista)??

If yes, then you should have mentioned that! Could have saved us quite some time. The behaviour of Windows Vista could have changed regarding the handling of STDOUT in the DOS box. Then there is no way for AutoIT to capture the Output, especially if even the DOS box can output the whole text only after the tool has been terminated.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

BTW: Are you running your script on Windows Vista (imagex seems to be a new tool for Vista)??

If yes, then you should have mentioned that! Could have saved us quite some time. The behaviour of Windows Vista could have changed regarding the handling of STDOUT in the DOS box. Then there is no way for AutoIT to capture the Output, especially if even the DOS box can output the whole text only after the tool has been terminated.

Cheers

Kurt

Yes, you're right. It is a Vista deployment tool and it is still in beta. They have updated the beta to run in Windows XP, which is the platform I am using. Actually, I am running it in a PE environment which is handling STDOUT fine on other scripts. It is like the tool is buffering STDOUT stream before it is redirected. Yet, I clearly see the progress update on the dos window from 1 to 100%. Again, I know little about how to use AutoIt and even less (next to zero) about programming so my understanding of the whole thing could be way off.

Link to comment
Share on other sites

Yes, you're right. It is a Vista deployment tool and it is still in beta. They have updated the beta to run in Windows XP, which is the platform I am using. Actually, I am running it in a PE environment which is handling STDOUT fine on other scripts. It is like the tool is buffering STDOUT stream before it is redirected. Yet, I clearly see the progress update on the dos window from 1 to 100%. Again, I know little about how to use AutoIt and even less (next to zero) about programming so my understanding of the whole thing could be way off.

O.K., what happens if you omit "/scroll" (in the DOS box and with AutoIT)??

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Maybe your prorgam writes to STDERR and not STDOUT. StdoutRead() will then block until the program quits. Can you redirect the output of your program with > at the DOS prompt? If so, it writes to STDOUT. If not, it writes to STDERR.

Cheers

Kurt

Just for general trivia's sake, if you redirect with "2>&1" on a Windows commandline, STDERR is routed to STDOUT and goes wherever STDOUT is going.

:lmao:

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
Link to comment
Share on other sites

@psaltyds

Yes that code does work and shows everything, but I would need the msgbox (or splashtexton or progressset) to be in the while loop and updated as output in the DOS window is updated. That's what I can't get working.

You didn't say if the text showed up on the STDOUT or STDERR line of the message box in my example. Part of the point in using seperate variables to capture the two was to see which got what output.

Anyway, you can parse the output in the string within the loop to update anything else you want. I would start with copying it to a SplashText box or ToolTip, just to see when it comes up:

$foo = Run(@ComSpec & " /c c:\temp\runner.bat", "C:\temp\", @SW_HIDE, 2+4) ; handles to STDOUT and STDERR
$OutMsg = ""
$ErrMsg = ""
$Done = False
While 1
    $OutLine = StdOutRead($foo)
    If @error Then $Done = True
    $OutMsg &= $OutLine
    
    $ErrLine = StdErrRead($foo)
    If @error Then $Done = True
    $ErrMsg &= $ErrLine

    If $Done Then ExitLoop
    $SplashMsg = "STDOUT: " & $OutMsg & @CRLF & "ERROUT: " & $ErrMsg
    SplashTextOn("Output Progress", $SplashMsg, 400, 400, @DesktopWidth - 450, 450)
    sleep(10)   
Wend
msgbox(0,"Results","STDOUT: " & $OutLine & @CRLF & "ERROUT: " & $ErrLine)

This way will make it clear if you are getting the update as the program runs, or just all at once when it's done. It also shows doing something with the text inside the loop, so you can modify that part to update a progress bar or something.

:lmao:

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
Link to comment
Share on other sites

You didn't say if the text showed up on the STDOUT or STDERR line of the message box in my example. Part of the point in using seperate variables to capture the two was to see which got what output.

Anyway, you can parse the output in the string within the loop to update anything else you want. I would start with copying it to a SplashText box or ToolTip, just to see when it comes up:

$foo = Run(@ComSpec & " /c c:\temp\runner.bat", "C:\temp\", @SW_HIDE, 2+4) ; handles to STDOUT and STDERR
$OutMsg = ""
$ErrMsg = ""
$Done = False
While 1
    $OutLine = StdOutRead($foo)
    If @error Then $Done = True
    $OutMsg &= $OutLine
    
    $ErrLine = StdErrRead($foo)
    If @error Then $Done = True
    $ErrMsg &= $ErrLine

    If $Done Then ExitLoop
    $SplashMsg = "STDOUT: " & $OutMsg & @CRLF & "ERROUT: " & $ErrMsg
    SplashTextOn("Output Progress", $SplashMsg, 400, 400, @DesktopWidth - 450, 450)
    sleep(10)   
Wend
msgbox(0,"Results","STDOUT: " & $OutLine & @CRLF & "ERROUT: " & $ErrLine)

This way will make it clear if you are getting the update as the program runs, or just all at once when it's done. It also shows doing something with the text inside the loop, so you can modify that part to update a progress bar or something.

:lmao:

Well, I was pretty confident that the program was writing to STDOUT based on some earlier discussion. To be positive, I ran with your code and the program shows the text on STDOUT, all at once, after the program finishes running. It's starting to sound like this program handles STDOUT in a different manner than most other commandline programs.

Link to comment
Share on other sites

Well, I was pretty confident that the program was writing to STDOUT based on some earlier discussion. To be positive, I ran with your code and the program shows the text on STDOUT, all at once, after the program finishes running. It's starting to sound like this program handles STDOUT in a different manner than most other commandline programs.

From your original post:

The command shows on the console...

Progress 1%

Progress 2%

Progress 3%

etc.

Basically I'm trying to get the progress percent to show in a window (was planning on using splashtext or progresson)

Did that orinially mean you saw "Progess 1%" thru "Progress 100%" show suddenly after the program completed? If not, does "shows on the console" mean you opened a CMD window, ran it, and saw that progress there while it was running? This is ceasing to make sense... :lmao:

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...