PowerShell.exe can hang if STDIN is redirected
Votes from Connect: 26
Original Date Submitted: 7/2/2010 7:56:48 AM
Handle: Jason Stangroome
Site Name: PowerShell
Feedback ID: 572313
Frequency: Sometimes Happens
Regression: I don't know if this issue existed previously
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.
Product Studio item created by Connect Synchronizer due to creation of feedback ID 572313 (http://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=572313).
1. Create a simple PowerShell script.
2. Create a batch file which calls the PowerShell script via:
powershell.exe -noninteractive -file <path to ps1 file>
3. Create a C# console application that runs the batch file using ProcessStartInfo with the RedirectStandardInput property set to true.
The batch file and the console app should exit successfully when the PowerShell script completes. Instead PowerShell hangs waiting for input on the redirected STDIN stream and the cmd.exe hosting the batch file and the C# application will both wait indefinitely.
Internal BugId: 2593