GoodName
asked on
conditional execution of commands in a batch file
Hi,
I have a question related to .BAT (batch) file processing.
I need to execute several commands (like isql and sqlldr) in a batch.
Does DOS (MS Windows XP) have a possibility to verify if previous command has been executed successfully and only then execute next command?
It should be kind of IF statement in DOS.
I have a question related to .BAT (batch) file processing.
I need to execute several commands (like isql and sqlldr) in a batch.
Does DOS (MS Windows XP) have a possibility to verify if previous command has been executed successfully and only then execute next command?
It should be kind of IF statement in DOS.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Also offhand, any particular reason you can't use WSH?
-saige-
-saige-
We'll see...
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
When I run this:
net start w32time&&echo Hello
Hello is not started, because I'm in Vista and I get "access denied".
net start w32time&&echo Hello
Hello is not started, because I'm in Vista and I get "access denied".
"Hello is not started" should be:
Hello is not displayed
That is exactly how the && works...
Hello is not displayed
That is exactly how the && works...
Check out this for more information that will help you to understand:
http://www.robvanderwoude.com/condexec.html
http://www.robvanderwoude.com/condexec.html
Steve I understand what you are saying... But, && will not always prevent the next command from running as I use the NET STOP "some service" && NET START "some service" all the time... The reason why && does not work in this case is because the command that is refferenced is the NET command... Does NET have a sub command called START... Yes it does, no error... If on the other hand I specified NET 1 or NET PULL or NET, your method would work... On vista you are getting an error Access Denied is because of the User Access Security... But do the same on an XP or earlier system and you will see exactly what I mean...
-saige-
-saige-
Your code is no different (abet more verbose) then mine with the &&.
I ran this on my XP Pro machine:
net start w32time&&echo Hello
It displays:
The requested service has already been started.
More help is available by typing NET HELPMSG 2182
It doesn't print Hello.
Have you tried that?
I ran this on my XP Pro machine:
net start w32time&&echo Hello
It displays:
The requested service has already been started.
More help is available by typing NET HELPMSG 2182
It doesn't print Hello.
Have you tried that?
ASKER
Thank you guys for your timely help!
Your welcome GoodName...
weareit any comment? Perhaps I'm missing something, if so I'd like to know so that I can understand what you are saying. Thanks :)
using && does not garruntee the results you are most likely looking for...
What you would want to do is either use an application which takes the results from the software and returns something that you can set as a variable to pass to your Batch file. You can also experiment with ERRORLEVEL in your batch file as most applications will return an ERRORLEVEL to the operating system.
http://www.computerhope.com/jargon/e/erroleve.htm
-saige-