Jump to content
Sign in to follow this  
iNFERiON

Get output from Run

Recommended Posts

iNFERiON

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
MrCreatoR

Hi!

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, "")
_GUICtrlStatusBarSetSimple($ProgressStatus)

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

GUISetState()

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

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
    WEnd
    If $Msg = $RunRarButton Then
        ProcessClose($ReadRar)
        GUICtrlSetData($Progress, 0)
    EndIf
    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) & ")"
    EndIf
    _GUICtrlStatusBarSetText($ProgressStatus, $DoneMsg, 255)
EndFunc


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]
    Next
    Return $RetNumber
EndFunc
Edited by MsCreatoR

 

Spoiler

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

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

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
 
AutoIt_Icon_small.pngExamples: 
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 === *

==================================================
My_Userbar.gif
==================================================

 

 

 

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  

×