Waiting between batch files

Toshiba / Pa3489u
April 29, 2009 at 19:07:30
Specs: Windows Vista, dual core
Hi...

I use one main batch file, that executes 9 other smaller batch files... so that each one can run and complete before going on to the next (required). At the end of each a flag file is created (%temp%\#)... a signal to record the time (log.txt) and go on to the next task/batch file.

Here is part of the main batch file:


:TASK1
set Task1=FILECOUNT
@Start /MIN %TEMP%\FILE_COUNT.bat
set /a wait=1 & Goto :Wait

:TASK2
set Task2=FILEMOVE
@Start /MIN %TEMP%\FILE_MOVE.bat
set /a wait=2 & Goto :Wait

.
.
.

ETC. ETC. to task9

.
.
.

:TaskFinish... more to do here, cleanup, etc.


:wait
cls
set flag=
set starttime=%time%
call :time ms_start "%starttime%"
:stop
color 3f
TITLE !Task%wait%! ... PLEASE WAIT
:waitloop
@IF EXIST %temp%\# goto :logdatetime
::ECHO A PERIOD W/O CARRIAGE RETURN/LINE FEED
(SET /P i=.) < NUL
PING 127.0.0.1 -N 2 -w 1000 > NUL
PING 127.0.0.1 -N 2 -W 1000 > NUL
PING 127.0.0.1 -N 2 -w 1000 > NUL
PING 127.0.0.1 -N 2 -W 1000 > NUL
PING 127.0.0.1 -N 2 -w 1000 > NUL
PING 127.0.0.1 -N 2 -W 1000 > NUL
PING 127.0.0.1 -N 2 -w 1000 > NUL
PING 127.0.0.1 -N 2 -W 1000 > NUL
@GOTO WAITLOOP

:logdatetime
set flag=2
set end=%time%
call :time ms_end "%end%"

:WAITCHOICE
If %wait%'==9' DEL %temp%\# & GOTO TASKFINISH
set /a next=%wait%+1
DEL %temp%\# & GOTO TASK%next%

:time <resultVar> <time>
SETLOCAL
for /L %%c in (1,1,4000) DO set something=%%c*3
FOR /F "tokens=1,2,3,4 delims=:,.^ " %%a IN ("%~2") DO (
set /a ms=^(^(^(30%%a%%100^)*60+7%%b^)*60+3%%c-42300^)*1000+^(1%%d0 %% 1000^)
)
(
ENDLOCAL
set %~1=%ms%
)
if "%flag%" == "2" goto :ElapsedTime
GOTO :STOP

:ElapsedTime
SET /a rounded_s=((ms_end-ms_start)+500)/1000
If %rounded_s% geq 3600 GOTO HOURS
If %rounded_s% geq 60 GOTO MINUTES

:SECONDS
Set elapsed=%rounded_s%sec & GOTO ReportElapsed

:MINUTES
set /a rounded_m=%rounded_s%/60
set /a rounded_s=%rounded_s%-(%rounded_m%*60)
set elapsed=%rounded_m%min%rounded_s%sec & GOTO ReportElapsed

:HOURS
set /a rounded_h=%rounded_s%/3600
set /a rounded_m=(%rounded_s%-(%rounded_h%*3600))/60
set /a rounded_s=(%rounded_s%-(%rounded_h%*3600))-(%rounded_m%*60)
set elapsed=%rounded_h%hrs%rounded_m%min%rounded_s%sec & GOTO ReportElapsed

:ReportElapsed
call echo.!Task%wait%! Started:%starttime% Finished:%end% Elapsed:%elapsed%>>%TEMP%\Log.txt & GOTO WAITCHOICE

-------

what I would like is a separate batch file (called wait.bat) that the main batch file could call when a wait was required (between the smaller tasks)... and I would want to return to the main batch file (where it left off... to the next task) once the wait is over. Kind of like this:

:TASK1
set Task1=FILECOUNT
@Start /MIN %TEMP%\FILE_COUNT.bat
set /a wait=1 & call %temp%\wait.bat

:TASK2
set Task2=FILEMOVE
@Start /MIN %TEMP%\FILE_MOVE.bat
set /a wait=2 & call %temp%\wait.bat

-------

so start file_count.bat, then wait.bat, then once complete file_count.bat creates its' flag file (#) resulting in wait.bat recording the time, (Ending) and returning back to the main batch file to start task2, etc.

Is this possible to do? I am lost on where to start. Does anyone else use a better wait method? Thank you for your time and help.


See More: Waiting between batch files

Report •


#1
April 29, 2009 at 19:25:20
uh... right

Without plowing throu all 134 linrs, if you want the main bat to wait for the others, just CALL them.


=====================================
If at first you don't succeed, you're about average.

M2


Report •

#2
April 29, 2009 at 23:51:03
If you need the scripts to start in their own windows you could add the /wait switch to the start commands.

Report •

#3
April 30, 2009 at 06:58:52
I know I'm a novice and may be writing my scripts incorrectly, but I had ne other question... does the call command, or the start /wait, work in all instances?... by work I mean does the called smaller batch file completely finish, before the main batch file proceeds on to the next task. I ask this because it seems I have had problems in the past where the main batch file would keep going right on to the next task before the prior was finished... hence why I am using flag file method... and I believe I tried using start /wait, but this wouldn't execute all tasks... hence my question... does it always work? Is there not a way to do it as I asked prior? Thank you for your help and responses.

Report •

Related Solutions

#4
April 30, 2009 at 08:04:01
CALL is for bat files and it always waits for the CALLed bat to finish.


=====================================
If at first you don't succeed, you're about average.

M2


Report •


Ask Question