Solved

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

Posted on 2004-09-09
8
594 Views
Last Modified: 2008-01-09
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
Comment
Question by:bob001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 3

Assisted Solution

by:Sasho
Sasho earned 40 total points
ID: 12019310
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
 

Author Comment

by:bob001
ID: 12020378
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
 
LVL 8

Expert Comment

by:Here2Help
ID: 12021343
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
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 

Author Comment

by:bob001
ID: 12021498
Here2Help,
If I use start, how do I know the return status of the program I wait for?
0
 

Accepted Solution

by:
HandsomeBob earned 20 total points
ID: 12034032
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
 
LVL 38

Expert Comment

by:BillDL
ID: 12039156
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
 

Expert Comment

by:HandsomeBob
ID: 12039717
Good to see you around again Bill :o)  - You been hiding? :P
0
 
LVL 38

Expert Comment

by:BillDL
ID: 12040157
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
robocopy for today files 14 223
bat script to copy folder from network to users public directory 10 50
Robocopy command line 6 69
Date variable in batch file 2 61
The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question