Solved

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

Posted on 2012-03-27
3
1,947 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
ID: 37775560
What does the output look like?
0
 

Author Comment

by:2newbie
ID: 37779145
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
ID: 37779504
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 80
Currency Conversion? 1 73
Please explain: Aspect Oriented Programming 2 85
Is doing tutor.com teaching in my situation advisable? 2 58
This article will show, step by step, how to integrate R code into a R Sweave document
This is an explanation of a simple data model to help parse a JSON feed
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

863 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

26 Experts available now in Live!

Get 1:1 Help Now