• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 603
  • Last Modified:

Need help! DOS Batch file to wait for another program to finish

I need a DOS batch file to do such:  start at 5am in the morning, but wait for another program to finish, when the other program finishs, if the status of the other program is a success, then pass a success output, otherwise pass a failure out.
Could someone drop a sample code to help out?
Thanks.
0
bob001
Asked:
bob001
  • 2
  • 2
  • 2
  • +2
2 Solutions
 
SashoCommented:
call another_program.exe
if errorlevel 1 goto error
if errorlevel 0 goto no_error

:error
echo Got an error
goto end

:no_error
echo It's all good!
:end
0
 
bob001Author Commented:
This would work.  Do you know any other mechanism of checking the status of another program other than running it within the script, such as passing a flag in a enviroment variable?
0
 
Here2HelpCommented:
Hey.

Try the code below to wait for a program to terminate before processing rest of batch.

Start /wait x:\path\file.


For help with start use the Start /?  switch.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
bob001Author Commented:
Here2Help,
If I use start, how do I know the return status of the program I wait for?
0
 
HandsomeBobCommented:
you mean the errorlevel right?

After starting the program, like so:

start another_program.exe
set err=%errorlevel%

now you just do whatever you want with the %err% variable.

Typically, if it's successful, the %err% variable would be 0, else, and error. You can do something dependant on the errorlevel, like so:

if %err%==0 (
   :: No error. Do whatever ...
) ELSE (
   :: An error. Do whatever ...
)

Or, if each process would envolve using more scopes, then use this:

if %err%==0 goto :NOERROR

:: Do whatever here for if there is an error.
goto :EOF

:NOERROR

:: Do whatever here for if there is no error.

:EOF
exit /b


Best of luck,
-B
0
 
BillDLCommented:
To assist with the actual scheduling of the batch file, Eric Phelps created a simple command line scheduler.

Download it, unzip it to any folder, and read the "readme.txt" file for the syntax.  It uses an .ini file that can easily be tailored to suit your needs.

http://www.ericphelps.com/schedule/schedule.zip
0
 
HandsomeBobCommented:
Good to see you around again Bill :o)  - You been hiding? :P
0
 
BillDLCommented:
Nope, I hide most of the time in the place I know best - Windows 98 topic area, but have the occasional foray into other areas to see if I know enough to make any sensible and useful suggestions  :-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now