欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Powershell實現(xiàn)捕獲系統(tǒng)內(nèi)置EXE程序的異常

 更新時間:2014年12月20日 12:12:30   投稿:junjie  
這篇文章主要介紹了Powershell實現(xiàn)捕獲系統(tǒng)內(nèi)置EXE程序的異常,系統(tǒng)內(nèi)置的EXE程序是指如robocopy.exe、ipconfig.exe等命令的實現(xiàn)程序,需要的朋友可以參考下

支持所有版本。

當(dāng)你運行控制臺EXE命令,如robocopy.exe, ipconfig.exe或類似命令。你可以用Powershell獲得他們引起的錯誤:

復(fù)制代碼 代碼如下:

try
{
    $current = $ErrorActionPreference
    $ErrorActionPreference = 'Stop'
    # this will cause an EXE command to emit an error
    # (replace with any console-based EXE command)
    net.exe user nonexistentUser 2>&1
    $ErrorActionPreference = $current
}
catch
{
   Write-Host ('Error occured: ' + $_.Exception.Message)
}

要捕獲錯誤你需要設(shè)置$ErrorActionPreference 為$stop,與此同時,你需要更改錯誤的輸出方式添加“2>&1”
這樣設(shè)置后,你就可以通過Powershell捕獲.net中的錯誤了。

相關(guān)文章

最新評論