2017-04-06 48 views
1

我正在執行以下7 Zip命令,這需要大約3-4小時才能完成,然後使用$ lastexitcode確保壓縮成功。這是做這件事的正確方法嗎?我發現$ lastexitcode不總是爲0,但壓縮文件看起來很好。

別的什麼可以修改此退出代碼?

& $7z a -tzip -mx=1 $destinationdir\$today.zip $destinationdir\$db1 >$null 2>&1 
if ($lastexitcode -ne 0){ 
... 

在 '> $空2> & 1' 只是用來所以我不認爲從7拉鍊的輸出。

感謝您的任何幫助。

+0

關於7zip的退出代碼:HTTP:// 7zip的.bugaco.com/7zip/MANUAL/exit_codes.htm –

+0

@DavidBrabant +1。這裏是源代碼中的退出代碼定義:[ExitCode.h](https://github.com/pornel/7z/blob/master/CPP/7zip/UI/Common/ExitCode.h)。 – beatcracker

回答

0

我通常使用另一種方法,如:

$process = Start-Process notepad.exe -PassThru -Wait 

然後使用

$process.ExitCode 

試試這個:

$process = Start-Process $7z -PassThru -Wait -ArgumentList "a -tzip -mx=1 $destinationdir\$today.zip $destinationdir\$db1 >$null 2>&1" 
if ($process.ExitCode -ne 0) { ....} 
+0

謝謝,這是有效的,除了我必須從參數列表中刪除'> $ null 2>&1',否則退出代碼總是1或2。 – warnox