Windows 批处理文件 && 运算符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6908448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows batch file && operator
提问by fieldtensor
In bash I can write this:
在 bash 中,我可以这样写:
#!/bin/sh
ant debug && adb install -r bin/Rocher-debug.apk
But I have a similar windows batch file, and currently it does this:
但是我有一个类似的 Windows 批处理文件,目前它是这样做的:
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?
因此,如果“ant debug”失败,它仍然会运行“adb install”,这并不理想。你们中有人知道如何在这种情况下做 && 等价物吗?
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 :-)
我真的必须在不久的将来坐下来正确地学习 Windows 脚本,因为我将在几个月内完成大量的 Windows 工作。但是现在快速回答会很棒:-)
回答by sorpigal
In cmd.exe the &&
operator should work essentially the same way, provided your program returns error codes correctly.
在 cmd.exe 中,&&
操作符应该以相同的方式工作,前提是您的程序正确返回错误代码。
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.
如果它在成功时返回零,否则返回非零,那么您可以使用与&&
在 bash 中使用的完全相同的方法。
回答by Dimitre Radoulov
Check the ant debugsuccess value in Windows ant debug; echo %errorlevel%
and then use: if errorlevel <prev_value> adb install ...
. Most likely the success value will be 0.
在 Windows 中检查ant debugsuccess 值ant debug; echo %errorlevel%
,然后使用:if errorlevel <prev_value> adb install ...
。成功值很可能为 0。