How to make parent program wait for command tofinish

Tags:
Microsoft Windows XP
Hi, I am relatively new to batch programming but need some simple (I believe) assistance. I need to have the following occur: STOP a service do a system backup of certain files START the service However, I don't want to start the service until the system backup is complete. How can I ensure that the backup is complete before the start line is executed? thanks in advance for all your help!!

Answer Wiki

Thanks. We'll let you know when a new response is added.

*** Updated by Wrobinson on 2/29/08 ***

This is sound advice, but my question is have you experienced that control is returned prior to the backup job finishing? Despite the answer, there are a couple of ways to accomplish this. The first would be as outlined below. Additionally, you can call another batch file from within the running batch file; it will execute and return control to the original batch file once it completes. Lastly, you can configure a backup job and in the job, specify actions to take before and after the job completes. So you could initiate the STOP before the job and then the START once it completes. If there are multiple services that must be stopped and started, you can simply call a ‘stop’ and ‘start’ batch file before and after the backup job respectively.

*** End Update ***

If by batch you mean a .BAT file, then what you have asked for is the default behavior.

For example, consider this:

net stop server
md c:\logbackups
copy c:\windows\*.log c:\logbackups\*.log
net start server

Some applications when called from a batch command will turn control of the batch back to the command processor (cmd.exe, command.com, explorer.exe, etc) before they have completed because they are multithreaded. You can get around this by using the <i>cmd</i> executable itself to execute the command. for example:

net stop server
md c:\logbackups
<i><b>cmd /c “command string you want to run”</b></i>
net start server

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following