2017-09-22 56 views
0

我有這行代碼,我很困惑它如何工作。我相信它會運行,但這不是我想要的,&& 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)',你的下一步將進入下一步 –

回答

3

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'的失敗執行嗎? –