Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an Batch file .bat continue onto the next statement if there is an error

Tags:

batch-file

I'm trying to script the shutdown of my VM Servers in a .bat. if one of the vmware-cmd commands fails (as the machine is already shutdown say), I'd like it to continue instead of bombing out.

c:
cd "c:\Program Files\VMWare\VmWare Server"

vmware-cmd C:\VMImages\TCVMDEVSQL01\TCVMDEVSQL01.vmx suspend soft -q
vmware-cmd C:\VMImages\DevEnv\DevEnv\DevEnv.vmx suspend soft -q
vmware-cmd C:\VMImages\DevEnv\TCVMDEV02\TCVMDEV02.vmx suspend soft =q


robocopy c:\vmimages\ \\tcedilacie1tb\VMShare\DevEnvironmentBackups\ /mir /z /r:0 /w:0

vmware-cmd C:\VMImages\TCVMDEVSQL01\TCVMDEVSQL01.vmx start
vmware-cmd C:\VMImages\DevEnv\DevEnv\DevEnv.vmx start 
vmware-cmd C:\VMImages\DevEnv\TCVMDEV02\TCVMDEV02.vmx start
like image 591
AndyM Avatar asked Sep 16 '08 16:09

AndyM


3 Answers

Run it inside another command instance with CMD /C

CMD /C vmware-cmd C:\...

This should keep the original BAT files running.

like image 161
chakrit Avatar answered Oct 21 '22 11:10

chakrit


If you are calling another batch file, you must use CALL batchfile.cmd

like image 22
kenny Avatar answered Oct 21 '22 11:10

kenny


Have you tried using "start (cmd)" for each command you are executing?

like image 41
Jen A Avatar answered Oct 21 '22 12:10

Jen A