Windows批处理文件中的"&&"运算符

9

在Bash中,我可以这样写:

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

但是我有一个类似的Windows批处理文件,目前它会执行以下操作:
ant debug
adb install -r bin/Rocher-debug.apk

所以,如果“ant debug”失败了,它仍然会运行“adb install”,这不是理想的解决方案。在这种情况下,你们中有人知道如何执行“&&”吗?
我真的很想坐下来好好学一下Windows脚本,因为几个月后我会做很多Windows工作。但现在,一个快速的答案就足够了。:-)

当你学习Windows批处理脚本时,也要看看PowerShell。 - aphoria
2个回答

11

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

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

应该可以工作。

你可以通过以下方式进行测试:

ant debug
echo %errorlevel%
如果成功时返回零,否则返回非零值,则可以在使用Bash时使用完全相同的&&

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接