Page 1 of 1
Progress bar during shell command
Posted: Mon Mar 01, 2010 10:22 pm
by larryh
Hi,
I have a stack where I record a begin time and end time of running a shell command every time I run the command. I calculate the LastRunTotalTime. What I would like to be able to do is use this figure to display a progress bar while the shell command is running in the background. I can't figure out how to get the two processes to run at the same time from the same script. Any ideas?
Something along the lines of this:
Code: Select all
on mouseUp
start progress bar incrementing
shell(DOSInstructions.exe)
end progress bar incrementing
exit mouseUp
Thanks,
Larry
Re: Progress bar during shell command
Posted: Mon Mar 01, 2010 10:30 pm
by Janschenkel
Sorry to disappoint you, Larry, but you cannot update a progressbar during a shell call - the shell completely takes over the event processing and window drawing loop. Which means that you can only update the progress bar just before and just after the shell call.
Depending on the DOS executable you are running, you could switch from the straightforward shell call to process communication, using the open process, read from process, write to process and close process commands? This would give you the opportunity to update the progressbar in between reads and writes.
Best of luck,
Jan Schenkel.
Re: Progress bar during shell command
Posted: Mon Mar 01, 2010 11:20 pm
by larryh
Thanks Jan, that's exactly what I was looking for. The process functionality works great!
Re: Progress bar during shell command
Posted: Tue Mar 02, 2010 1:24 am
by larryh
Well, it almost works. There are some processes that output nothing to the cmd line window except perhaps a line feed or EOF I am assuming at the end. These work fine with the following script:
Code: Select all
on ProgressBarWithProcess pStartValue, pEndValue, pProcess, pProgressBarName, pHideOnCompletion, pEndProcessString
-- This handler shows progress on a progress bar while a process is running the background.
-- pStartValue - where should the progress bar start. In a sequences of processes, use to start at a higher start value.
-- pEndValue - where should the progress bar end. Assumes that seconds are the time unit.
-- pProcess - name/path of the process to execute.
-- pProgressBarName - name of the scrollbar/progress bar object
-- pHideOnCompletion - 1 or 0. Hides the progress bar once completed.
-- pEndProcessString - Optional. String that is normally output in a DOS window when the process is complete.
set visible of scrollbar pProgressBarName to true
set startValue of scrollbar pProgressBarName to 0
set endValue of scrollbar pProgressBarName to pEndValue
put pProcess into vLaunchedProcess
open process vLaunchedProcess
repeat until vLaunchedProcess is not among the lines of the openProcesses
repeat with vCurrentValue = 0 to pEndValue
set the thumbPosition of scrollbar pProgressBarName to vCurrentValue
wait 1 sec
if vLaunchedProcess is not among the lines of the openProcesses then
set the thumbPosition of scrollbar pProgressBarName to pEndValue
exit repeat
end if
end repeat
end repeat
wait 1 sec
-- if pHideOnCompletion is 1 then set the visible of scrollbar pProgressBarName to false
end ProgressBarWithProcess
Unfortunately, when the process actually does output something to the DOS Window, then it does not work. For example, one of my DOS commands outputs "Finished in xx.xxxxxx seconds." when complete.
How and where would I put the read from process until, let's say the string is "Finished."
Larry
Re: Progress bar during shell command
Posted: Tue Mar 02, 2010 6:50 am
by Janschenkel
If you use the form
Code: Select all
open process vLaunchedProcess for read
then you can
Code: Select all
read from process vLaunchedProcess for 1 line
if the process closes its output with a newline character.
Beware of looping while a process is in the openProcesses - if the command-line application doesn't exit by itself, but waits for your app to send it a certain string, it may very well deadlock.
Jan Schenkel.