Home Dashboard Directory Help
Search

PowerShell.exe can hang if STDIN is redirected by J. Stangroome


Status: 

Active


22
0
Sign in
to vote
Type: Bug
ID: 572313
Opened: 7/1/2010 5:52:56 PM
Access Restriction: Public
4
Workaround(s)
view
11
User(s) can reproduce this bug

Description

The Microsoft.PowerShell.ConsoleHost class constructs a M.PS.WrappedDeserializer passing the STDIN TextReader as one of the parameters. By default, the WrappedDeserializer will call ReadLine() on this STDIN TextReader and wait indefinitely, effectively hanging PowerShell and the calling process.
Details
Sign in to post a comment.
Posted by Greg Borota on 11/17/2012 at 8:34 AM
With this workaround you don't have to use use undocumented features:

powershell.exe -file ScriptFile.ps < CON
Posted by Peter Moberg on 11/21/2010 at 12:40 PM
I have the same problem when executing PowerShell from MSDeploy:

http://stackoverflow.com/questions/4238192/running-powershell-from-msdeploy-runcommand-does-not-exit/4239192#4239192

Using the suggested "-inputformat none" seems to resolve the problem.
Sign in to post a workaround.
Posted by Patrick R Nielsen on 6/3/2013 at 11:04 AM
If you upgrade to PowerShell V3 the process works correctly from my testing. My not be an option for everyone but seems good option if you have a lot of legacy script wrappers.
Posted by Greg Borota on 11/17/2012 at 8:32 AM
InputFormat None is undocumented while piping (|) workaround won't allow passing arguments to PS script file.
This workaround addresses both of these issues:

powershell.exe -file <path to ps1 file> -args < CON
Posted by Derek Meek on 6/21/2011 at 2:24 PM
to work around this bug:

type yourinputfile.ps1 | Powershell -Command ^-

Posted by J. Stangroome on 7/1/2010 at 5:55 PM
Passing "none" to the "inputformat" parameter of powershell.exe causes the WrappedDeserializer to skip the ReadLine() call on the redirected STDIN. For example:
powershell.exe -inputformat none -file <path to ps1 file>

However, "none" is not documented as a valid value for the "inputformat" parameter and one would have expected the "noninteractive" parameter switch to achieve a similar result.