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
Solved

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

Posted on 2012-03-27
3
1,994 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

839 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