Computer Hope

Microsoft => Microsoft DOS => Topic started by: nigelben on March 06, 2009, 10:33:03 AM

Title: Wait for command to complete before contining batch file
Post by: nigelben on March 06, 2009, 10:33:03 AM
I have created a batch file with the following syntax

call  c:\maxl\batch\inflation.bat

@echo off

:begin
febootimail -FROM [email protected] -TO [email protected] -MSG "Inflation Cubes are complete. Please do not respond to this message as it is sent from an unmonitored account." -SUBJECT "Inflation Cubes complete"  -SMTP THCNOTES

if not errorlevel 5 goto end
echo Couldn't connect to server. Trying again...
goto begin

:end
echo End of batch program.

the first line calls another batch file which runs an essbase maxl script in a dos window, the problem is that when it runs the script it calls the 2nd batch file and that closes as soon as it has called the maxl script, I need a way to make the called batch file wait until the maxl script has run its course , is there anyway to make it wait until the script has run
Title: Re: Wait for command to complete before contining batch file
Post by: DaveLembke on March 06, 2009, 12:21:37 PM
If you know how long it takes for that process to complete you can use a number of ways to make it count x number of seconds before continuing.

Would a preset time delay work for you?
Title: Re: Wait for command to complete before contining batch file
Post by: nigelben on March 06, 2009, 12:30:41 PM
not really, I need to know the time it is complete and then an email sent, the process could take 30 minutes to an hour based on server usage
Title: Re: Wait for command to complete before contining batch file
Post by: Reno on March 06, 2009, 10:56:09 PM
i tested the following code, and call statement  does calling another batch, and return to the caller once finished.
Code: [Select]
@echo off
(
echo echo inflation bat start
echo ping 127.0.0.1 ^>nul
echo echo inflation bat finish
)>#.bat

call #.bat
echo return from call statement

so i suspect "inflation.bat" contain some command that run windows program in its own thread/process. or it might contain nt dos command such as "start","%comspec%", or "cmd" which create a new instance.
Title: Re: Wait for command to complete before contining batch file
Post by: GuruGary on March 08, 2009, 10:22:53 PM
How about changing your CALL batch file command to:

Code: [Select]
start /wait cmd /C "c:\maxl\batch\inflation.bat"
Title: Re: Wait for command to complete before contining batch file
Post by: nigelben on March 09, 2009, 09:16:56 AM
@echo off
(
echo echo inflation bat start
echo ping 127.0.0.1 ^>nul
echo echo inflation bat finish
)>#.bat

call #.bat
echo return from call statement

this command is rewriting the inflation.bat file to read

echo echo inflation bat start
echo ping 127.0.0.1 ^>nul
echo echo inflation bat finish
Title: Re: Wait for command to complete before contining batch file
Post by: Reno on March 09, 2009, 09:40:12 AM
this command is rewriting the inflation.bat file to read

 ??? ??? ???

it's just an example to proof that call statement does wait for a batch file to finish executing before returning.
if you can post the code of inflation.bat, maybe someone can help you.
Title: Re: Wait for command to complete before contining batch file
Post by: GuruGary on March 09, 2009, 11:52:09 AM
I think the code in Reply #4 should work for any code in the "inflation.bat" file.