Solved

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

Posted on 2012-03-27
3
2,038 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This is about my first experience with programming Arduino.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

734 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