2016-10-29 31 views
1

如果我跑,如果文件夾不存在Erroraction不能與多個命令

Remove-Item .\somefolder -force -Recurse -erroraction 'silentlycontinue'

什麼都不會被顯示的工作,但如果我跑

Remove-Item .\somefolder -force -Recurse -erroraction 'silentlycontinue'; otherCommand

我得到「Remove- Item:找不到路徑'路徑',因爲它不存在。「

如何抑制錯誤?

編輯:我發現問題只發生在我從Visual Studio包管理器控制檯運行命令時。

+0

你能解釋更多嗎?什麼是其他命令,因爲我測試了它。這是完整的工作沒有錯誤 – saftargholi

+0

@arashzgh你是對的,我編輯我的問題 – user764754

+0

我寫答案,它的工作很好只是把你的路徑在「./path」在雙嬰兒牀 – saftargholi

回答

0

如果使用dublecot「./somefolder」它做工精細,沒有任何錯誤:

Remove-Item ".\Somefolder" -force -Recurse -erroraction 'silentlycontinue';somecommand 

或使用單嬰兒牀:如果你想爲多個命令的錯誤行爲偏好然後

Remove-Item '.\Somefolder' -force -Recurse -erroraction 'silentlycontinue';somecommand 
0

您可以在執行這些命令之前設置erroractionpreference變量:

$ErrorActionPreference = "silentlycontinue" 

注:我假設你的其他命令是錯誤的原因