Sign in to follow this  
Followers 0
Tiboi

help needed with progress for commandline app

39 posts in this topic

ok this script have given me a headace. can anyone please help me with this script?

I am trying to make a progressbar for a commandline app that runs showing percentages of its progress.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

Global $totalTicks

#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 413, 298, 192, 131)
$Progress1 = GUICtrlCreateProgress(128, 184, 150, 17)
$Input1 = GUICtrlCreateInput("Input1", 112, 24, 137, 21)
$Button1 = GUICtrlCreateButton("Button1", 168, 248, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            progress()
    EndSwitch
WEnd

Func progress() ;<--
    Local $Browse = GUICtrlRead($Input1) ;<--
    If $Browse = "" Then ;<--If no file path in $Input1 the if loop ends
    Else
        $maxTicks = 11 ;<-- Set the max number of % to expect from 0% - 100% = 11
        Local $comexe = Run(@ScriptDir & "commandlineprogram.exe", @SW_HIDE, 2) ;<--
        While 1
            Local $readTicks = StdoutRead($comexe) ;<--Read from the child's STDOUT
            If @error = -1 Then ExitLoop ; <--if StdoutRead sets @error to -1 we're at EOF, so exit
            StringReplace($readTicks, "%", "0") ; <--StringReplace keeps a count of chars it replaces in @extended
            Local $totalTicks += @extended ; <-- Dont know what that's for
            Local $tickPercent = (($totalTicks / $maxTicks) * 100) ; <--Calculate something
            GUICtrlSetData(-1, $tickPercent) ; <--Adjust the progress bar
        WEnd
        Sleep(500)
        ProgressOff() ;<--Hide the progress bar
        MsgBox(0, "Debug", "Done.")
        ; Finished
    EndIf
EndFunc   ;==>progress

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Change this too :

Local $comexe = Run(@ScriptDir & "\commandlineprogram.exe", @SW_HIDE, 2) 
Local $readTicks, $tickPercent, $totalTicks
        
While ProcessExists ( $comexe )
    $readTicks = StdoutRead($comexe) 
    If Not @error And $readTicks <> '' Then
    StringReplace($readTicks, "%", "0")
    $totalTicks =+ @extended
    $tickPercent = (($totalTicks / $maxTicks) * 100)
    GUICtrlSetData(-1, $tickPercent) 
    EndIf
WEnd

What's your commandline app ?

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

this is a screen shot of what the commandline app look like

Posted Image

i want to run the app, hide this and show a progress in my main app.

i tried this code but it still does not work. any more ideas please?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>


#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("Form2", 413, 298, 192, 131)
$Progress1 = GUICtrlCreateProgress(128, 184, 150, 17)
$Input1 = GUICtrlCreateInput("Input1", 112, 24, 137, 21)
$Button1 = GUICtrlCreateButton("Button1", 168, 248, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            progress()
    EndSwitch
WEnd
Func progress() ;<--
    ;Local $Browse = GUICtrlRead($Input1) ;<--
    ;If $Browse = "" Then ;<--If no file path in $Input1 the if loop ends
    ;Else
        $maxTicks = 80 ;<-- Set the max number of % to expect from 0% - 100% = 11
        Local $comexe = Run(@ScriptDir & "\commandlineprogram.exe", @SW_HIDE, 2)
        Local $readTicks, $tickPercent, $totalTicks

        While ProcessExists($comexe)
            $readTicks = StdoutRead($comexe)
            If Not @error And $readTicks <> '' Then
                StringReplace($readTicks, "%", "0")
                $totalTicks = +@extended
                $tickPercent = (($totalTicks / $maxTicks) * 100)
                GUICtrlSetData(-1, $tickPercent)
            EndIf
        WEnd
        ;MsgBox(0, "Debug", "Done.")
    ;EndIf;### Tidy Error -> "endfunc" is closing previous "if" on line 27
EndFunc   ;==>progress

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Try changing this:

GUICtrlSetData(-1, $tickPercent)

To This:

GUICtrlSetData($Progress1, $tickPercent)

still dont work.

Edited by Tiboi

Share this post


Link to post
Share on other sites

can someone create a script that will show a command-line window displaying percentages from 1 - 100 so that debugging scripts like mine with progress bars would be easier. something like the command line screen shot i have above.

Share this post


Link to post
Share on other sites

This is probably just a parsing error in your code. Use ConsoleWrite or MsgBox to display the raw data that you are receiving from the StdoutRead calls and post it.

Share this post


Link to post
Share on other sites

This is probably just a parsing error in your code. Use ConsoleWrite or MsgBox to display the raw data that you are receiving from the StdoutRead calls and post it.

consolewrite outputs a LOT of this: 76417641764176417641764176417641764176417641764176417

Share this post


Link to post
Share on other sites

Ok Two things, While ProcessExists($comexe) won't work because the process is ran and exited before this block is even executed.

I made a commandlineapp. I used Aut2Exe with console checked as an option so it should write to a stream but it isn't being read by your script. I'm still working on this so maybe we'll work it out. I'll try a c/c++ program too to see if that makes a difference.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

GOT IT!

Put this exe in your script directory:

Be sure to back up your original commandlineprogram.exe!

(after you DL this I'm going to delete it because it takes up too much room)

And then use this modified code:

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -d 
#AutoIt3Wrapper_Run_Tidy=y
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

Global $totalTicks, $nMsg = ''

#region ### START Koda GUI section ### Form=
Global $Form2 = GUICreate("Form2", 413, 298, 192, 131)
Global $Progress1 = GUICtrlCreateProgress(128, 184, 150, 17)
Global $Input1 = GUICtrlCreateInput("Input1", 112, 24, 137, 21)
Global $Button1 = GUICtrlCreateButton("Button1", 168, 248, 75, 25, $WS_GROUP)
GUISetState()
#endregion ### END Koda GUI section ###

Do
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $Button1
            progress()
    EndSwitch

    Sleep(20)
Until $nMsg = $GUI_EVENT_CLOSE

Exit

Func progress() ;<--
    Local $Browse = GUICtrlRead($Input1) ;<--

    If $Browse <> '' Then ;<--If no file path in $Input1 the if loop ends
        Local $maxTicks = 11 ;<-- Set the max number of % to expect from 0% - 100% = 11
        Local $comexe = Run("commandlineprogram.exe", @ScriptDir, @SW_HIDE, 2) ;<--
        Local $readTicks, $tickPercent

        While 1
            $readTicks = StdoutRead($comexe)

            If @error Then ExitLoop

            If $readTicks <> '' Then
                ConsoleWrite($readTicks & @CRLF)
                StringReplace($readTicks, "%", "0")
                $totalTicks += @extended
            EndIf

            $tickPercent = (($totalTicks / $maxTicks) * 100)
            GUICtrlSetData($Progress1, $tickPercent)
        WEnd

        Sleep(500)

        ProgressOff() ;<--Hide the progress bar
        MsgBox(0, "Debug", "Done.")
        ; Finished
    EndIf
EndFunc ;==>progress
Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

thanks this works. i'll edit it to suit my app thanks a bunch

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

No problem, we'll talk about how much you owe over lunch, m'kay?

lol

i had to do some serious modding to get it to work in my app but i finally got it.

now another problem: if i hit the button once its ok but if i hit it again it dont do the same thing over. the progress bar stays full and the message box comes up quicker. any ideas?

oh and my tool will be free. you just tell me where to post it but i am not sharing the source:)

Edited by Tiboi

Share this post


Link to post
Share on other sites

The ProgressOff() won't work in this case because you need to use ProgressOn() to create the progress bar (but dont quote me on that).

Try using GUICtrlSetData($progress1, 0) in place of ProgressOff().

Share this post


Link to post
Share on other sites

You can remove the ProgressOff() line. It's not required with a GUI Progrees bar


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Here is a simpler method that should do the same thing.

Func progress() ;<--
    Local $Browse = GUICtrlRead($Input1) ;<--

    If $Browse <> '' Then ;<--If no file path in $Input1 the if loop ends
        Local $sSTO, $sPercent
        Local $comexe = Run("commandlineprogram.exe", @ScriptDir, @SW_HIDE, 2) ;<--

        While 1
            $sSTO = StdoutRead($comexe)
            If @error Then ExitLoop
        $sPercent = StringRegExpReplace($sSTO, ".*(\d+)%(?:\v|\z)+", "$1")
            If GUICtrlRead($Progress1) <> $sPercent Then GUICtrlSetData($Progress1, $sPercent)
        WEnd

        Sleep(500)
        MsgBox(0, "Debug", "Done.")
        ; Finished
    EndIf
EndFunc ;==>progress

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

Here is a simpler method that should do the same thing.

Func progress() ;<--
    Local $Browse = GUICtrlRead($Input1) ;<--

    If $Browse <> '' Then ;<--If no file path in $Input1 the if loop ends
        Local $sSTO, $sPercent
        Local $comexe = Run("commandlineprogram.exe", @ScriptDir, @SW_HIDE, 2) ;<--

        While 1
            $sSTO = StdoutRead($comexe)
            If @error Then ExitLoop
        $sPercent = StringRegExpReplace($sSTO, ".*(\d+)%(?:\v|\z)+", "$1")
            If GUICtrlRead($Progress1) <> $sPercent Then GUICtrlSetData($Progress1, $sPercent)
        WEnd

        Sleep(500)
        MsgBox(0, "Debug", "Done.")
        ; Finished
    EndIf
EndFunc ;==>progress

tried your code like this but the progress bar showed nothing

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

Global $totalTicks, $nMsg = '', $Browse

#Region ### START Koda GUI section ### Form=
Global $Form2 = GUICreate("Form2", 413, 298, 192, 131)
Global $Progress1 = GUICtrlCreateProgress(128, 184, 150, 17)
Global $Input1 = GUICtrlCreateInput("Input1", 112, 24, 137, 21)
Global $Button1 = GUICtrlCreateButton("Button1", 168, 248, 75, 25, $WS_GROUP)
GUISetState()
#EndRegion ### END Koda GUI section ###

Do
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $Button1
            progress()
    EndSwitch

    Sleep(20)
Until $nMsg = $GUI_EVENT_CLOSE

Exit
Func progress() ;<--
    Local $Browse = GUICtrlRead($Input1) ;<--

    ;If $Browse <> '' Then ;<--If no file path in $Input1 the if loop ends
        Local $sSTO, $sPercent
        Local $comexe = Run("commandlineprogram.exe", @ScriptDir, @SW_HIDE, 2) ;<--

        While 1
            $sSTO = StdoutRead($comexe)
            If @error Then ExitLoop
        $sPercent = StringRegExpReplace($sSTO, ".*(\d+)%(?:\v|\z)+", "$1")
            If GUICtrlRead($Progress1) <> $sPercent Then GUICtrlSetData($Progress1, $sPercent)
        WEnd

        Sleep(500)
        MsgBox(0, "Debug", "Done.")
        ; Finished
    ;EndIf
EndFunc ;==>progress

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

Okay, we change the RegExp (remember we don't have your commandline file to test) so it works like this

Func progress() ;<--
    Local $Browse = GUICtrlRead($Input1) ;<--

    If $Browse <> '' Then ;<--If no file path in $Input1 the if loop ends
        Local $sSTO, $sPercent
        Local $comexe = Run("commandlineprogram.exe", @ScriptDir, @SW_HIDE, 2) ;<--

        While 1
            $sSTO = StdoutRead($comexe)
            If @error Then ExitLoop
            $sPercent = StringRegExpReplace($sSTO, ".+([1-9]0+)%", "$1")
            If @Extended Then
                If GUICtrlRead($Progress1) <> $sPercent Then GUICtrlSetData($Progress1, $sPercent)
            EndIf
        WEnd

        Sleep(500)
        MsgBox(0, "Debug", "Done.")
        ; Finished
    EndIf
EndFunc ;==>progress

There are just so many ways to do this. Since the image you showed has it incrementing in steps of 10 this should also be correct.

Func progress() ;<--
    Local $Browse = GUICtrlRead($Input1) ;<--

    If $Browse <> '' Then ;<--If no file path in $Input1 the if loop ends
        Local $sSTO, $iPercent
        Local $comexe = Run("commandlineprogram.exe", @ScriptDir, @SW_HIDE, 2) ;<--

        While 1
            $sSTO = StdoutRead($comexe)
            If @error Then ExitLoop
            StringReplace($sSTO, "%")
            $iPercent = @Extended
            If $iPercent > 1 Then
                $iPercent = ($iPercent -1) *10
                If GUICtrlRead($Progress1) <> $iPercent Then GUICtrlSetData($Progress1, $iPercent)
            EndIf
        WEnd

        Sleep(500)
        MsgBox(0, "Debug", "Done.")
        ; Finished
    EndIf
EndFunc ;==>progress
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

ok try this exact script with the commandlineprogram.exe above you will see the problem i have.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

Global $totalTicks, $nMsg = '';, $Browse

#Region ### START Koda GUI section ### Form=
Global $Form2 = GUICreate("Form2", 413, 298, 192, 131)
Global $Progress1 = GUICtrlCreateProgress(128, 184, 150, 17)
Global $Input1 = GUICtrlCreateInput("Input1", 112, 24, 137, 21)
Global $Button1 = GUICtrlCreateButton("Button1", 168, 248, 75, 25, $WS_GROUP)
GUISetState()
#EndRegion ### END Koda GUI section ###

Do
    $nMsg = GUIGetMsg()

    Switch $nMsg
        Case $Button1
            progress()
    EndSwitch

    Sleep(20)
Until $nMsg = $GUI_EVENT_CLOSE

Exit

Func progress() ;<--
    ;Local $Browse = GUICtrlRead($Input1) ;<--

    ;If $Browse <> '' Then ;<--If no file path in $Input1 the if loop ends
    Local $sSTO, $iPercent
    Local $comexe = Run("commandlineprogram.exe", @ScriptDir, @SW_HIDE, 2) ;<--

    While 1
        $sSTO = StdoutRead($comexe)
        If @error Then ExitLoop
        StringReplace($sSTO, "%")
        $iPercent = @extended
        If $iPercent > 1 Then
            $iPercent = ($iPercent - 1) * 10
            If GUICtrlRead($Progress1) <> $iPercent Then GUICtrlSetData($Progress1, $iPercent)
        EndIf
    WEnd

    Sleep(500)
    MsgBox(0, "Debug", "Done.")
    ; Finished
    ;EndIf
EndFunc   ;==>progress

edit: i guess it was removed. well here is a copy

http://www.mediafire.com/?ygjhzdn2dfm
Edited by Tiboi

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