mdwerne Posted December 17, 2014 Share Posted December 17, 2014 Hello, I'm working on a simple progress bar that displays the progress when formatting a drive. Specifically when using the format command for a multipass "wipe" (format /p:1). Here's my code, the problem I'm having is that I cannot seem to isolate the percentage complete from StdoutRead, I get multiple lines returned from the read, that my trim command misses the correct data. If this make sense to anyone, can you see a way to fix my issue, or is there a better way to display a progress bar during a long format ("wipe") of a drive? WARNING!! If you have a "Z" drive on your machine, you may wipe out your data if you blindly run this code!!! Global $format, $getPercent, $PercentComplete = 0 ;don't uncomment the next line unless you know what you're doing! ;$format = Run(@ComSpec & " /c echo y | format /p:1 /x /v:Wiped z:", "", @SW_HIDE,2) ProgressOn("Progress", "Formatting and Wiping Drive...") While 1 $getPercent = StdoutRead($format) If StringInStr($getPercent, "Format complete") Then ExitLoop ;example string from $getPercent "17 percent completed." $PercentComplete = StringTrimRight($getPercent, 19) ProgressSet(($PercentComplete / 100) * 100) WEnd ProgressSet(100, "Done", "Success!") Sleep(3000) ProgressOff() MsgBox(0, "Success!", "Format and Wipe Complete!") Thanks for taking a look! -Mike Link to comment Share on other sites More sharing options...
hSarvesh Posted December 17, 2014 Share Posted December 17, 2014 You might want to add some delay in While 1 loop so that you can free some resources for your format command.... otherwise its a going in checking.. checking.. checking.. nothing you will be able to see i believe.. just a suggestion.. Link to comment Share on other sites More sharing options...
mdwerne Posted December 17, 2014 Author Share Posted December 17, 2014 You might want to add some delay in While 1 loop so that you can free some resources for your format command.... otherwise its a going in checking.. checking.. checking.. nothing you will be able to see i believe.. just a suggestion.. Good suggestion, had a 10 second delay, but that exacerbated my issue. Removed it for testing. I think I found my solution, need to add a stringright ($PercentComplete) after the trim command. Working the correct values now. Thanks again for the suggestion. -Mike Link to comment Share on other sites More sharing options...
Solution mdwerne Posted December 18, 2014 Author Solution Share Posted December 18, 2014 (edited) Ok...a little more effort on my part and this is what I ended up with: Global $format, $getPercent, $PercentComplete = 0 ;$format = Run(@ComSpec & " /c echo y | format /p:1 /x /v:Wiped z:", "", @SW_HIDE,2) ProgressOn("Formatting and Wiping Drive", "This process may take a long time...") While 1 $getPercent = StdoutRead($format) If StringInStr($getPercent, "Format complete.") Then ExitLoop $PercentComplete = StringTrimRight($getPercent, 35) $PercentComplete = StringRight($PercentComplete, 2) $PercentComplete = StringStripWS($PercentComplete, 8) If StringIsDigit($PercentComplete) then ProgressSet($PercentComplete) sleep(5000) WEnd ProgressSet(100, "Format and Wipe Complete", "Success!") Sleep(3000) ProgressOff() MsgBox(0, "Success!", "The Format and Wipe has completed successfully!") While there may be better ways to accomplish the same task, this one seems to be good enough for government work. -Mike Edited December 18, 2014 by mdwerne 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