如何正确使用多个||,&,&&

问题描述:

我有这行代码,我很困惑它如何工作。我相信它会运行,但这不是我想要的,&& goto continue只会在电子邮件失败时运行,因为它是最接近的代码块。如何正确使用多个||,&,&&

我想从这条线上测试一个.zip的完整性,如果它成功执行goto continue,如果不是,它会发送一封电子邮件(blat)然后退出。

"c:\Program Files\7-Zip\7z.exe" t %ZIPFILE% | FIND "Everything is Ok" || blat -to [email protected] -server mail.protection.outlook.com -f [email protected] -subject "Backup integrity check failed" -body "failed" && goto continue 

也许我需要的是一个代码,如果> else块,但是,我想,以确保有没有办法做到这一点只是条件执行。

谢谢!

+0

你的'continue'标签在哪里?我认为它更好/更清楚地写成'(检查zip文件)|| (blat&goto:EOF)',你的下一步将进入下一步 –

From Windows XP documentation:

&

用法:command1 & command2

摘要:用于多个命令的一个命令行分离。

& &

用法:command1 & & command2

摘要:使用运行command2只有command1是成功的。

||

用法:command1 || command2

摘要:仅当command1失败时才用于运行command2

达到你想要什么,只要交换条件代码:

"c:\Program Files\7-Zip\7z.exe" t %ZIPFILE% | FIND "Everything is Ok" && goto continue || blat -to [email protected] -server mail.protection.outlook.com -f [email protected] -subject "Backup integrity check failed" -body "failed" 

这样,如果成功的话会继续以其他方式发送电子邮件。

+0

我以前怎么没有想过那个!感谢一堆,有一个aewsome的一天!我只有一个问题,goto continue后面的'||'会根据'find'的失败执行吗? –