Sign in to follow this  
Followers 0
ReDFlaG

progress bar & dos

7 posts in this topic

$foo = Run(@ScriptDir &'\app.exe /wipe', '', @SW_HIDE, 7)

ProgressOn("Erasing...", "", "0 percent")
While 1
     $line &= StdoutRead($foo)
         If @error = -1 Then ExitLoop
WEnd
ProgressOff()

I launch a dos prog that wipe the disk. It output its copyright then a % into a dos box to show its progress.

How can i can i do to make a progress bar that match its own increment?

I know i must use ProgressSet( $i, $i & " percent"), but how can i use it properly in that case? (Each stdout then +1%)

Thanks.

Share this post


Link to post
Share on other sites



You'd have to know how many % signs you have, how many it draws when it's done, then cross-multiply with 100 to get the current percent:

$currentPercent = Round(($currentSigns / $maxSigns) * 100)

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

If the rate of the % signs is constant then this should work (so i build the progress bar before the stdoutread).

So if you propose this way to do, it's because it's impossible to increment a var each time the dos prog send something to the stdoutRead ? (and then can't do a "realtime" progress bar but an approximately one) ?

Thanks for the answer.

Share this post


Link to post
Share on other sites

If the rate of the % signs is constant then this should work (so i build the progress bar before the stdoutread).

So if you propose this way to do, it's because it's impossible to increment a var each time the dos prog send something to the stdoutRead ? (and then can't do a "realtime" progress bar but an approximately one) ?

Thanks for the answer.

The rate doesn't have to be constant, but yes, you'd initialize your progress bar at 0% before running your app or at least before reading from STDOUT, as you've done in you example.

What I proposed would need to be in your While loop that reads from STDOUT many times, each time adding the number of % signs that it read at that time to a total of all the % signs read, then performing the above calculation to see what percent complete the job was currently reporting to be, then updating the progress bar, then repeating the loop.


Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

While StdoutRead($foo)
;$currentPercent = Round(($currentSigns / $maxSigns) * 100)
;ProgressSet( $currentPercent, $currentPercent & " percent")
     MsgBox(0,"signal","signal +1")
     If @error = -1 Then ExitLoop
WEnd

I tried that, so anytime the dos prog stdout something, a msgbox should popup, but that's not the case. So i can't see how to code that part since when the dos prog launch and start formating the disk, the script seems to do nothing.

Edit:

found that in the manual "the StdoutRead function will block (pause) and not return until there are characters to be read from the stream. This means that the AutoIt process will be halted, and there will be no processing of hotkeys, GUI messages, etc. until the child process writes something to the STDOUT stream."

Edited by ReDFlaG

Share this post


Link to post
Share on other sites

While StdoutRead($foo)
;$currentPercent = Round(($currentSigns / $maxSigns) * 100)
;ProgressSet( $currentPercent, $currentPercent & " percent")
     MsgBox(0,"signal","signal +1")
     If @error = -1 Then ExitLoop
WEnd

I tried that, so anytime the dos prog stdout something, a msgbox should popup, but that's not the case. So i can't see how to code that part since when the dos prog launch and start formating the disk, the script seems to do nothing.

Edit:

found that in the manual "the StdoutRead function will block (pause) and not return until there are characters to be read from the stream. This means that the AutoIt process will be halted, and there will be no processing of hotkeys, GUI messages, etc. until the child process writes something to the STDOUT stream."

@error is reset every time a function is called, so you're testing the @error result of MsgBox(), so your loop will likely never exit.

StdoutRead doing a blocking read shouldn't be a problem; we're only waiting for the child program to write something, and all we should care about doing at that stage is updating the progress bar.

Please try this:

Dim $maxTicks, $totalTicks, $readTicks, $process

; Set the max number of % to expect
$maxTicks = 80

; Run the child process, connecting to its STDOUT pipe
$process = Run(@ScriptDir & "\%progress.exe", @ScriptDir, @SW_HIDE, 2)

; Show the progress bar
ProgressOn("% Count", "Counting...")

; Read from the child's STDOUT
While 1
    $readTicks = StdoutRead($process)
   ; if StdoutRead sets @error to -1 we're at EOF, so exit
    If @error = -1 Then ExitLoop
    StringReplace($readTicks, "%", "0")
   ; StringReplace keeps a count of chars it replaces in @extended
    $totalTicks += @extended
   ; Adjust the progress bar
    ProgressSet(($totalTicks / $maxTicks) * 100)
WEnd

; Hide the progress bar
ProgressOff()

MsgBox(0, "Debug", "Done.")
; Finished

%progress.exe, writes 80 % characters to STDOUT over 4 seconds:

Dim $tick

ConsoleWrite("Starting." & @CRLF)

; Write 80 % signs to STDOUT over 4 seconds
For $tick = 1 To 80
    ConsoleWrite("%")
    Sleep(60)
Next

ConsoleWrite(@CRLF & "Done." & @CRLF)

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Share this post


Link to post
Share on other sites

it works perfectly! thanks a lot! :lmao:

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