Sign in to follow this  
Followers 0

Get output from Run

2 posts in this topic

#1 ·  Posted (edited)

Hey all, I'm pretty new to AutoIt, but I'm really liking the ease of learning it so far. I am creating a GUI installation script for a program and it's for 90% done. The last thing I want to add is a Progressbar that keeps track of the progress of extraction, so the user can see that something is acutally happening, since this is a long process. I have the progressbar added to my GUI, but what I can't figure out is if and how it's possible to have the progressbar get it's value from an external process. I am running the DOS version of RAR to extract a set of rar files.

Now this is how I call the RAR application:

$extract = RunWait(@TempDir & "\rar.exe x stpdta.001 " & ControlGetText("", "", $path))

Everytime a volume is done extracting the DOS application ($extract) says "Extracting from file2 ... Extracting from file3" and so on... Is there a way I can can "catch" those messages so I can set the progressbar to move on a little bit? This will give the user the idea that something is actually happening.

Edited by iNFERiON

Share this post

Link to post
Share on other sites

#2 ·  Posted (edited)


Try this example, i think it will help you to understand how it can be done (it's not a perfect example, but it is wery basic help wih things that you trying to do :whistle: ) :

#include <GuiStatusBar.au3>

$RarPath = @ScriptDir & "\Rar.exe"
$ArchiveName = @ScriptDir & "\Test.rar"
$FilesToAdd = '"C:\My Documents" "C:\Test"'

$Gui = GUICreate("Add files to archive", 500, 200)

$Progress = GUICtrlCreateProgress(40, 45, 430, 20)
$ProgressStatus = _GUICtrlStatusBarCreate($Gui, 0, "")

$RunRarButton = GUICtrlCreateButton("Add files...", 220, 80)


While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3
        Case $RunRarButton
            $ReadRar = Run($RarPath & ' a "' & $ArchiveName & '" ' & $FilesToAdd, "", @SW_HIDE, 2)
            GUICtrlSetData($RunRarButton, "Abort")

Func AddFiles()
    While 1
        $Msg = GUIGetMsg()
        $ReadRarLine = StdoutRead($ReadRar)
        If @error Or $Msg = $RunRarButton Then ExitLoop
        _GUICtrlStatusBarSetText($ProgressStatus, "Add files process... " & $ReadRarLine, 255)
        GUICtrlSetData($Progress, _StringStripNotNumber($ReadRarLine))
        $LastRead = $ReadRarLine
    If $Msg = $RunRarButton Then
        GUICtrlSetData($Progress, 0)
    GUICtrlSetData($RunRarButton, "Add files...")
    $DoneMsg = "Done!"
    If StringInStr($LastRead, "Warning") Or StringInStr($LastRead, "Error") Then
        If StringInStr($LastRead, "Warning") Then $ErrPos = StringInStr($LastRead, "Warning")
        If StringInStr($LastRead, "Error") Then $ErrPos = StringInStr($LastRead, "Error")
        $DoneMsg = "Done! (" & StringTrimLeft($LastRead, $ErrPos-2) & ")"
    _GUICtrlStatusBarSetText($ProgressStatus, $DoneMsg, 255)

Func _StringStripNotNumber($String)
    If Not IsString($String) Then Return $String
    Local $i, $RetNumber, $AllStringArr = StringSplit($String, "")
    For $i = 1 To $AllStringArr[0]
        If StringRegExp($AllStringArr[$i], '^ *([0-9]+\.{0,1}[0-9]*|0x[0-9]+) *$') Then $RetNumber &= $AllStringArr[$i]
    Return $RetNumber
Edited by MsCreatoR



Using OS: Win 7 Professional, Using AutoIt Ver(s): /

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...


AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *





AutoIt is simple, subtle, elegant. © AutoIt Team

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