2012-07-23 16 views
2
PS C:\> start regedit -ArgumentList '/S', 'D:\resources\hawk_config.reg' -Wait 
Start-Process : Process with an Id of 5344 is not running. 
At line:1 char:6 
+ start <<<< regedit -ArgumentList '/S', 'D:\resources\hawk_config.reg' 
    + CategoryInfo   : NotSpecified: (:) [Start-Process], ArgumentException 
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.StartProcessCommand 

我無法弄清楚它是什麼。有任何想法嗎?啓動過程:Id爲5344的進程未運行

+0

你可以試試'start-process'嗎? – Spooky 2012-07-23 21:33:08

+0

'start'是'start-process'的別名 – 2012-07-23 21:49:40

+0

我想,但我認爲這是值得一試的。如何使用'''而不是''' – Spooky 2012-07-23 22:05:55

回答

3

/S參數是否會導致regedit一旦合併.reg文件就立即退出?我懷疑你得到的錯誤是因爲在啓動過程有機會在過程對象上調用Process.WaitForExit()之前,regedit已經退出。通過在命令後面運行$error[0] | Format-List *來查看錯誤的大腸。如果進程已退出,則WaitForExit()將拋出SystemException。我無法在PowerShell v3上重現這一點。也許他們解決了這個cmdlet的一個問題。

作爲一種解決方法可以嘗試:

$p = start-process regedit -ArgumentList '/S', 'D:\resources\hawk_config.reg' -passthru 
$p.WaitForExit() 
0

WaitForExit()會拋出構造一個SystemException如果進程已經退出。

我在一個循環中使用啓動進程的PS腳本中隨機獲取這個相同的東西。從來沒有在同一次迭代,有時從來沒有。這可以完美地解釋這種行爲。線程和進程的隨機異步計時。

我嘗試了建議的錯誤信息轉儲,它看起來像它證實的想法,過程整理WaitForExit()獲取看到它之前:

開始處理:無法處理請求,因爲該進程( 38152)已退出。

$結果=啓動過程< < < < -FilePath $編譯-ArgumentList $ argstr -nonewwindow -PassThru -wait CategoryInfo:NotSpecified:(:) [起動處理],出現InvalidOperationException + FullyQualifiedErrorId信息:System.InvalidOperationException ,Microsoft.PowerShell.Commands.StartProcessCommand

相關問題