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我搞不懂这是什么。有什么想法吗?
发布于 2012-07-24 12:57:35
/S参数不会导致regedit在合并.reg文件后立即退出吗?我怀疑您得到的错误是因为在Start-Process有机会在process对象上调用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()发布于 2014-12-19 01:43:21
如果进程已经退出,WaitForExit()将抛出SystemException。
我在一个在循环中使用start-process的PS脚本中随机地得到了同样的东西。从不在相同的迭代中,有时根本不会。这将完美地解释这种行为。线程和进程的随机异步计时。
我尝试了建议的错误消息转储,它似乎证实了进程在WaitForExit()看到它之前就已经结束的想法:
Start-Process :无法处理请求,因为进程(38152)已退出。
$result = start-process <<<< -filepath $compiler -argumentlist $argstr -nonewwindow -passthru -wait CategoryInfo : NotSpecified:(:) Start-Process,InvalidOperationException + FullyQualifiedErrorId : System.InvalidOperationException,Start
https://stackoverflow.com/questions/11620591
复制相似问题