Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows batch file && operator

In bash I can write this:

#!/bin/sh
ant debug && adb install -r bin/Rocher-debug.apk

But I have a similar windows batch file, and currently it does this:

ant debug
adb install -r bin/Rocher-debug.apk

So, if "ant debug" fails, it will still run "adb install," and that's not ideal. Do any of you guys know how to do an && equivalent in this situation?

I really have to sit down and properly learn windows scripting some day soon, since I'll be doing a lot of windows work in a few months. But for now a quick answer would be awesome :-)

like image 225
fieldtensor Avatar asked Aug 02 '11 07:08

fieldtensor


People also ask

What is .bat and .EXE file?

EXE files are different from BAT files since they contain executable binary data rather than plain text commands. They are stored in the Portable Executable (PE) format. The EXE file format includes various headers and sections that tell Windows how to run a program.


1 Answers

In cmd.exe the && operator should work essentially the same way, provided your program returns error codes correctly.

ant debug && adb install -r bin/Rocher-debug.apk

Should work.

You can test this the following way:

ant debug
echo %errorlevel%

If this returns zero when it succeeded and non-zero otherwise, then you can use the exact same && that you use in bash.

like image 64
sorpigal Avatar answered Oct 06 '22 23:10

sorpigal