PowerShell 使 exe 命令无效?
我错误地使用以下 PowerShell 构造来捕获 stdout:
$output = devenv.exe .....
或者,如果我将 exe 作为函数参数调用:
obj.LogOutput((devenv.exe ...))
执行这些命令中的任何一个后,在同一命令窗口中执行的所有未来命令都不会执行任何操作。例如,如果我运行 devenv、echo 或 xcopy,它们会立即返回而不执行。如果我运行“devenv /?”没有产生任何输出。如果我关闭命令窗口并启动一个新窗口,一切都会恢复正常。我能够再次执行这些命令。
什么给?我知道语法不正确,但 PowerShell 从未在语法上出错。相反,在执行后续 EXE 时,它会默默地失败(顺便说一句,PowerShell 命令继续工作)。我的语法对 PowerShell 造成如此严重的影响怎么办?我问这个问题主要是因为我再次看到这种行为,但我可以在我的脚本中找到上述任何构造。
更新:我最好的猜测是这个构造:
$o = new-object psobject
$o | add-member -force -memberType ScriptMethod -name Test -value { param($t) $t > c:\temp\output.txt" }
$o.Test((xcopy /?))
这与我的原始脚本中导致问题的代码行非常相似,但该代码独立不会重现该问题。无论如何,我认为我无法想象出任何语法可以使所有 EXE 都无法运行。
I mistakenly used the below PowerShell construct to capture stdout:
$output = devenv.exe .....
Or, if I invoke the exe as a function parameter:
obj.LogOutput((devenv.exe ...))
After either of these commands are executed, all future commands executed within the same command window do nothing. If I ran devenv, echo, or xcopy, for example, they immediately return without executing. If I run "devenv /?" no output was produced. If I closed the command window and started a new one everything returned to normal. I was able to execute these commands again.
What gives? I know the syntax is incorrect, but PowerShell never errored on the syntax. Instead it silently fails when executing subsequent EXEs (PowerShell commands continue to work, btw). What about my syntax tripped up PowerShell so bad? I ask mostly because I am seeing this behavior again but I can find any of the above constructs in my script.
Update: My best guess was this construct:
$o = new-object psobject
$o | add-member -force -memberType ScriptMethod -name Test -value { param($t) $t > c:\temp\output.txt" }
$o.Test((xcopy /?))
This was very similar to the line of code that was causing the problem in my original script, but this code standalone does not reproduce the problem. In any case, I would think there would be no syntax I could dream up that would render all EXEs inoperable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://social.technet.microsoft .com/Forums/en/winserverpowershell/thread/5148df55-b1bf-4eeb-a84c-ca0e1a728db4
显然存在将数组传递到写入主机的问题,该问题会破坏未来的命令输入。
http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/5148df55-b1bf-4eeb-a84c-ca0e1a728db4
Apparently there is an issue passing an array into write-host that corrupts future command input.