PowerShell 使 exe 命令无效?

发布于 2024-10-13 18:40:32 字数 782 浏览 2 评论 0原文

我错误地使用以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海之角 2024-10-20 18:40:32

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文