开发者

PowerShell renders exes commands inert?

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"开发者_JS百科 }
$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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜