Solved

AutoIT - Howto "translate" command line output to a gui progress bar output via AutoIT

Posted on 2012-03-27
3
1,922 Views
Last Modified: 2012-04-09
Is there a way and\or how would I go about "translating" the command output (for the progress) of this app (http://downloads.sourceforge.net/project/nfgdump/nfgdump/nfgdump-0.1/nfgdump-win32-binary.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnfgdump%2F&ts=1332884584&use_mirror=iweb) to a progress bar, via AutoIT?

nfgdump.exe " & $DumporRestore & " /v /p /c /g /o=gz /d=\Dev" & $Drive-X & " /f=t:\LinuxImageStore\" & $ImgName & ".img"

nfgdump.exe dump /v /p /c /g /o=gz /d=\Dev0 /f=c:\Images\myimage.img

Note: if possible, an example would prove most helpful.
0
Comment
Question by:2newbie
  • 2
3 Comments
 
LVL 29

Expert Comment

by:matrixnz
Comment Utility
What does the output look like?
0
 

Author Comment

by:2newbie
Comment Utility
the command output looks like this:



Dump of '\Dev0\1 (C:)' started: (UTC) Wed Mar 28 22:42:38 2012

1.69% (comp: 62.34%), 9.82 MB/s, finished in 01:03:11.



it is the first portion, section or parameter (the one that shows 1.69%) of the output that i wish to transfer into a progress bar. however, i would like the throughput (9.82 MB/s and finished in 01:03:11 displayed as well, if possible).

Thanks.
0
 
LVL 29

Accepted Solution

by:
matrixnz earned 500 total points
Comment Utility
Basically what needs to happen is you need to use STDOUT_CHILD to capture the output then you need to use StringSplit on the line using ',' as the delimiter.  This should give you an array with three  variables, you then use Number on the first variable to get 1.69 and then use Round to get a whole number, you can then update your progress bar with each of the three variables, i.e. $Var[1] = 2, $Var[2] = 9.82, $Var[3] = finished in 01:03:11

Below is an example, I haven't tested, but hopefully it'll get you started.
#include <Array.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

Global $GUI_PROGRESS, $GUI_BUTTON, $RUN_NFGDUMP, $GUI_DATASTREAM, $GUI_FINISHEDIN

Example()

Func Example()
	Local $STD_NFGDUMP
	Local $DumporRestore = 'Dump or Restore'
	Local $Drive_X = 'Drive Letter'
	Local $ImgName = 'Image Name'
    GUICreate("NFGDUMP", 320, 100, 100, 200)
	GUICtrlCreateLabel('NFG Dump or Restore', 10, 15, 300, 20)
	GUICtrlSetFont(-1, 9, 800)
    $GUI_PROGRESS = GUICtrlCreateProgress(10, 40, 300, 20, $PBS_SMOOTH)
    $GUI_BUTTON = GUICtrlCreateButton("Start", 240, 70, 70, 20)
	$GUI_DATASTREAM = GUICtrlCreateLabel('', 10, 70, 70, 20)
	$GUI_FINISHEDIN = GUICtrlCreateLabel('', 80, 70, 70, 20)
    GUISetState()

    Do
        $msg = GUIGetMsg()
        If $msg = $GUI_BUTTON Then
			$RUN_NFGDUMP = Run("nfgdump.exe " & $DumporRestore & " /v /p /c /g /o=gz /d=\Dev" & $Drive_X & " /f=t:\LinuxImageStore\" & $ImgName & ".img", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
			While 1
				$STD_NFGDUMP = StdoutRead($RUN_NFGDUMP)
					If @error Then ExitLoop
				If StringInStr($STD_NFGDUMP, 'finished in') Then FNC_PROGRESS($STD_NFGDUMP)
			WEnd
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
EndFunc

Func FNC_PROGRESS($PAR_NFGDUMP)
	Local $VAR_NFGDUMP
	$VAR_NFGDUMP = StringSplit($PAR_NFGDUMP, ',')
	If IsArray($VAR_NFGDUMP) And $VAR_NFGDUMP[0] = 3 Then
		GUICtrlSetData($GUI_PROGRESS, Round(Number($VAR_NFGDUMP[1])))
		GUICtrlSetData($GUI_DATASTREAM, $VAR_NFGDUMP[2])
		GUICtrlSetData($GUI_FINISHEDIN, $VAR_NFGDUMP[3])
		Sleep(1000)
	EndIf
EndFunc

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now