2011-08-02 308 views
6

在bash我可以这样写:Windows批处理文件&&操作

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

但我有一个类似Windows的批处理文件,目前它这样做:

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

所以,如果“蚁调试“失败,它仍然会运行”adb install“,这并不理想。在这种情况下,你们中的任何一个人都知道如何做一个相当于& &?

我真的不得不坐下来,很快就会学习windows脚本,因为我会在几个月内做很多windows的工作。但现在一个快速的答案将是真棒:-)

+0

在您正在学习Windows批处理脚本时,请查看PowerShell。 – aphoria

回答

0

检查在Windows ant debug; echo %errorlevel%蚂蚁调试成功值,然后使用:if errorlevel <prev_value> adb install ...。最有可能的成功值将为0.

9

在cmd.exe中,&&运算符应该以基本相同的方式工作,前提是程序正确返回错误代码。

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

应该工作。

您可以测试这种方式如下:

ant debug 
echo %errorlevel% 

如果返回零,当它成功了,否则返回非零值,那么你可以使用你在bash使用完全相同的&&