lhw Posted April 20, 2011 Share Posted April 20, 2011 (edited) edit:its solved via stderrread,thanks wakillon for the helpexpandcollapse popup#include <String.au3> #include <array.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> Global $sector, $dev GUICreate("ReadCD ProgressBar", 220, 100) $progressbar = GUICtrlCreateProgress(10, 10, 200, 20) $btn = GUICtrlCreateButton("do", 75, 70, 70, 20) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn $sector = 14299 $dev = '1,2,0' $sPath = 'readcd.exe dev=' & $dev & ' sectors=0-' & $sector & ' f=disk.out' $rtn = TestFile($sPath) ;ConsoleWrite($rtn) EndSwitch WEnd Func TestFile($sPath) Local $stderr, $stderrAll, $_Data1 Local $pid = Run ( 'cmd.exe /c "' & $sPath & '"', '', @SW_HIDE, 6 ) If Not $pid Then Return SetError(-1, 0, 'Failed to run') While ProcessExists ( $pid ) $stderr = StderrRead($pid, 0, 0) If Not @error Then $stderrAll &= $stderr $i = _StringBetween ( $stderr, 'addr:', ' cnt:' ) If Not @error Then $_Data1 = Round(Number ($i[0] )/$sector*100, 2); convert to % ConsoleWrite ( "-->-- $_Data1 : " & $_Data1 & @Crlf ) GUICtrlSetData ( $progressbar, $_Data1) EndIf EndIf WEnd GUICtrlSetData($Progressbar, 100) MsgBox(0, '', 'Bakup successfully') GUICtrlSetData($Progressbar, '') If Not $stderrAll Then Return SetError(-3, 0, 'Nothing to read') Return SetError(0, 0, $stderrAll) EndFunchello everyone,i'm trying to write a readcd GUI so that i can backup dashboard of my USB internet dongles , im trying to capture the outputs of the process so that can add a progressbar to the GUI,already worked around it a couple hours without success, readcd is a command line tool from CDRtools,it works for me very well,i can got the outputs with Consolewrite or Msgbox via the following codes, I'm confused if there is a way can capture each line that i can sent them to the progressbar,thanks in advance.$sPath = 'readcd.exe dev=2,1,0 sectors=0-500 f=disk.out' $rtn = TestFile($sPath) ConsoleWrite($rtn) ;MsgBox(0, '', $rtn) Func TestFile($sPath) Local $eMsg, $stdout Local $pid = Run('cmd.exe /c "' & $sPath & '"', '', @SW_HIDE, 6) If Not $pid Then Return SetError(-1, 0, 'Failed to run') ; While 1 $eMsg &= StderrRead($pid, 0, 0) If @error Then ExitLoop Sleep(10) WEnd If $eMsg Then Return SetError(-2, 0, $eMsg) ; While 1 $stdout &= StdoutRead($pid, 0, 0) If @error Then ExitLoop Sleep(10) WEnd If Not $stdout Then Return SetError(-3, 0, 'Nothing to read') Return SetError(0, 0, $stdout) EndFuncthe outputs just like the followingCapacity: 16384 Blocks = 32768 kBytes = 32 MBytes = 33 prMB Sectorsize: 2048 Bytes Copy from SCSI (2,1,0) disk to file 'disk.out' end: 500 addr: 0 cnt: 16 addr: 16 cnt: 16 addr: 32 cnt: 16 addr: 48 cnt: 16 .... .......... addr: 448 cnt: 16 addr: 464 cnt: 16 addr: 480 cnt: 16 addr: 496 cnt: 4 addr: 500 Time total: 0.229sec Read 1000.00 kB at 4366.8 kB/sec. Edited April 22, 2011 by lhw Link to comment Share on other sites More sharing options...
JohnOne Posted April 20, 2011 Share Posted April 20, 2011 Are you certain that 6 amounts to BitOr(0x2,0x4) ? AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
wakillon Posted April 20, 2011 Share Posted April 20, 2011 (edited) Try this :#include <String.au3> $sPath = 'readcd.exe dev=2,1,0 sectors=0-500 f=disk.out' $rtn = TestFile($sPath) ConsoleWrite($rtn) Global $progressbar Func TestFile($sPath) Local $eMsg, $stdout, $stdoutAll Local $pid = Run('cmd.exe /c "' & $sPath & '"', '', @SW_HIDE, 6) If Not $pid Then Return SetError(-1, 0, 'Failed to run') While ProcessExists ( $pid ) $eMsg = StderrRead($pid, 0, 0) If @error Then ExitLoop $stdout = StdoutRead($pid, 0, 0) If Not @error Then $stdoutAll &= $stdout $i = _StringBetween ( $stdout, 'addr:', ' cnt:' ) If Not @error Then GUICtrlSetData ( $progressbar, Number ( $i[0] ) ) ; i let you find the way to set percentage EndIf WEnd If Not $stdoutAll Then Return SetError(-3, 0, 'Nothing to read') Return SetError(0, 0, $stdoutAll) EndFuncEdit : Avoid using sleep in loop ! Edited April 20, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
lhw Posted April 21, 2011 Author Share Posted April 21, 2011 Try this : #include <String.au3> $sPath = 'readcd.exe dev=2,1,0 sectors=0-500 f=disk.out' $rtn = TestFile($sPath) ConsoleWrite($rtn) Global $progressbar Func TestFile($sPath) Local $eMsg, $stdout, $stdoutAll Local $pid = Run('cmd.exe /c "' & $sPath & '"', '', @SW_HIDE, 6) If Not $pid Then Return SetError(-1, 0, 'Failed to run') While ProcessExists ( $pid ) $eMsg = StderrRead($pid, 0, 0) If @error Then ExitLoop $stdout = StdoutRead($pid, 0, 0) If Not @error Then $stdoutAll &= $stdout $i = _StringBetween ( $stdout, 'addr:', ' cnt:' ) If Not @error Then GUICtrlSetData ( $progressbar, Number ( $i[0] ) ) ; i let you find the way to set percentage EndIf WEnd If Not $stdoutAll Then Return SetError(-3, 0, 'Nothing to read') Return SetError(0, 0, $stdoutAll) EndFunc Edit : Avoid using sleep in loop ! thanks Wakillon,now i knew how to obtain the data i need via your codes,but the process seem go the stderr way, would got nothing from stdout, i can't sent data to progressbar from a while loop,finally i made the progressbar works after the process end,apparently its not a right way, i need more help ,pls take a look at my new codes expandcollapse popup#include <String.au3> #include <array.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> Dim $i, $j, $t Dim $sector=14299 GUICreate("ReadCD ProgressBar", 220, 100) $progress = GUICtrlCreateProgress(10, 10, 200, 20) $btn = GUICtrlCreateButton("do", 75, 70, 70, 20) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btn $sPath = 'readcd.exe dev=1,2,0 sectors=0-'& $sector & ' f=disk.out' $rtn = TestFile($sPath) ;ConsoleWrite($rtn) ;MsgBox(0, '', _ArrayMaxIndex($i, 0, 1)) ;MsgBox(0, '', $t[0]) For $n = 0 To _ArrayMaxIndex($i, 0, 1) GUICtrlSetData($progress, number($i[$n]/$sector*100)) Sleep (1000*$t[0]/_ArrayMaxIndex($i, 0, 1)) Next GUICtrlSetData($Progress, 100) MsgBox(0, '', 'Bakup successfully') GUICtrlSetData($Progress, '') EndSwitch WEnd Func TestFile($sPath) Local $eMsg, $stdout, $eMsgs $pid = Run('cmd.exe /c "' & $sPath & '"', '', @SW_HIDE, 6) If Not $pid Then Return SetError(-1, 0, 'Failed to run') ; While ProcessExists($pid) $eMsg &= StderrRead($pid, 0, 0) If Not @error Then $eMsgs &= $eMsg $i = _StringBetween($eMsg, 'addr:', ' cnt:') $t = _StringBetween($eMsg, 'Time total: ', 'sec');get time of the process ;$s = _StringBetween($eMsg, ' = ', ' = ');get size of writable area Else ExitLoop EndIf WEnd If Not $eMsgs Then Return SetError(-3, 0, 'Nothing to read') If $eMsg Then Return SetError(-2, 0, $eMsg) EndFunc Link to comment Share on other sites More sharing options...
wakillon Posted April 21, 2011 Share Posted April 21, 2011 Why did you say you can't sent data to progressbar from a while loop ?you need to extract infos from StderrRead and send them... AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
lhw Posted April 21, 2011 Author Share Posted April 21, 2011 Why did you say you can't sent data to progressbar from a while loop ?you need to extract infos from StderrRead and send them...Just try again, i think i'm wrong about understanding the array get from stderrout outputs,just need find out one way to extract them,thanks Wakillon, ill give it further try:) Link to comment Share on other sites More sharing options...
wakillon Posted April 21, 2011 Share Posted April 21, 2011 (edited) Something like this ? #include <String.au3> $sPath = 'readcd.exe dev=2,1,0 sectors=0-500 f=disk.out' $rtn = TestFile($sPath) ConsoleWrite($rtn) Global $progressbar Func TestFile($sPath) Local $eMsg, $stderr, $stderrAll, $_Data1, $_Data2, $_Data3 Local $pid = Run ( 'cmd.exe /c "' & $sPath & '"', '', @SW_HIDE, 6 ) If Not $pid Then Return SetError(-1, 0, 'Failed to run') While ProcessExists ( $pid ) $stderr = StderrRead($pid, 0, 0) If Not @error Then $stderrAll &= $stderr $i = _StringBetween ( $stderr, 'addr:', ' cnt:' ) If Not @error Then $_Data1 = Number ( $i[0] ) ConsoleWrite ( "-->-- $_Data1 : " & $_Data1 & @Crlf ) EndIf $t = _StringBetween ( $stderr, 'Time total: ', 'sec');get time of the process If Not @error Then $_Data2 = Number ( $t[0] ) ConsoleWrite ( "+->-- $_Data2 : " & $_Data2 & @Crlf ) EndIf $s = _StringBetween ( $stderr, ' = ', ' = ' );get size of writable area If Not @error Then $_Data3 = Number ( $s[0] ) ConsoleWrite ( "!->-- $_Data3 : " & $_Data3 & @Crlf ) EndIf ; GUICtrlSetData ( $progressbar, $_Data1 & " " & $_Data2 & " " & $_Data3 ) ; i let you find the way to set percentage EndIf WEnd If Not $stderrAll Then Return SetError(-3, 0, 'Nothing to read') Return SetError(0, 0, $stderrAll) EndFunc Edited April 21, 2011 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
lhw Posted April 21, 2011 Author Share Posted April 21, 2011 (edited) Something like this ? #include <String.au3> $sPath = 'readcd.exe dev=2,1,0 sectors=0-500 f=disk.out' $rtn = TestFile($sPath) ConsoleWrite($rtn) Global $progressbar Func TestFile($sPath) Local $eMsg, $stderr, $stderrAll, $_Data1, $_Data2, $_Data3 Local $pid = Run ( 'cmd.exe /c "' & $sPath & '"', '', @SW_HIDE, 6 ) If Not $pid Then Return SetError(-1, 0, 'Failed to run') While ProcessExists ( $pid ) $stderr = StderrRead($pid, 0, 0) If Not @error Then $stderrAll &= $stderr $i = _StringBetween ( $stderr, 'addr:', ' cnt:' ) If Not @error Then $_Data1 = Number ( $i[0] ) ConsoleWrite ( "-->-- $_Data1 : " & $_Data1 & @Crlf ) EndIf $t = _StringBetween ( $stderr, 'Time total: ', 'sec');get time of the process If Not @error Then $_Data2 = Number ( $t[0] ) ConsoleWrite ( "+->-- $_Data2 : " & $_Data2 & @Crlf ) EndIf $s = _StringBetween ( $stderr, ' = ', ' = ' );get size of writable area If Not @error Then $_Data3 = Number ( $s[0] ) ConsoleWrite ( "!->-- $_Data3 : " & $_Data3 & @Crlf ) EndIf ; GUICtrlSetData ( $progressbar, $_Data1 & " " & $_Data2 & " " & $_Data3 ) ; i let you find the way to set percentage EndIf WEnd If Not $stderrAll Then Return SetError(-3, 0, 'Nothing to read') Return SetError(0, 0, $stderrAll) EndFunc thanks Wkillon, i use 'do ... until' or 'for... next' to extract data from array $i,if i set a larger sectors the process will stop at NO.171 and report error each time,i use _arraydisplay to display $i ,always 0-170 data dispalyed on firt page,if sleep more time ,would get more data but not all,the thing seem got to the dead end, is there other way can get the all data? Edit:it works now, i post a working script at 1st, thank you for the help,but i am still confused why couldn't extract all data at a time,otherwise the progressbar would get a good performance,i found a readcd gui with a perfect progressbar written in autoit ,unfortunately cant access the codes... Edited April 22, 2011 by lhw Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now