Leave the input/output/error handles unset when they are not redirected#20853
Leave the input/output/error handles unset when they are not redirected#20853daxian-dbw merged 2 commits intoPowerShell:masterfrom
Conversation
| var CLSID_EnumerableObjectCollection = new Guid(@"2d3468c1-36a7-43b6-ac24-d3f02fd9607a"); | ||
| const uint CLSCTX_INPROC_HANDLER = 2; | ||
| const uint CLSCTX_INPROC = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER; | ||
| var ComSvrInterface_GUID = new Guid(@"555E2D2B-EE00-47AA-AB2B-39F953F6B339"); |
There was a problem hiding this comment.
This variable is assigned but not used anywhere.
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList/TaskbarJumpList.cs
Show resolved
Hide resolved
iSazonov
left a comment
There was a problem hiding this comment.
What if user redirect only output?
Can we cover the scenario we fix by tests?
When starting
Existing tests for |
|
I'm pretty sure this change broke atuinsh/atuin#2543 - looks like letting Windows figure out the default handle to use doesn't always work as well as expected. 😢 In that PR, I want to redirect stderr to a file while keeping stdout on the screen. After updating PowerShell to v7.5.0, nothing appears on screen anymore on Windows. The following line now misbehaves: Start-Process -Wait -NoNewWindow -RedirectStandardError $resultFile.FullName -FilePath atuin -ArgumentList $argStringIf I understand correctly, there's no easy workaround for this. You can't supply a custom output handle to |
|
@ltrzesniewski Please open new issue with simple repro steps. |
|
Sure, sorry. Reported here: #24986 |
PR Summary
This PR is to fix
Start-Processto address PowerShell/PSReadLine#288.Basically, when starting
pwshwithStart-Processin the following ways, the new console and the existing console get weirdly tied together, which causesConsole.ReadKeyrunning in those 2 consoles to interfere with each other (block and unblock each other):Start-Process pwsh -RedirectStandardError .\error.txt: startpwshwith its stderr redirected to the fileerror.txtStart-Process pwsh -PassThru -Credential (Get-Credential <another-user>): startpwshas a different user.Based on the investigation in PowerShell/PSReadLine#288 (comment), we should not explicitly set the standard input/output/error handles when they are not redirected. Instead, just let Windows figure out the default to use when creating the process.
Note that, the change in
TaskbarJumpList.csis related. When runningStart-Process pwsh -Credentialas a non-admin user, the "TaskbarJumpList" code throwsAccessDeniedexception, which causes a debug build to crash. TheDebug.Failis not needed. Thecatch (ThreadStartException)below simply ignore the exception too.Manual validation
I verified the changes on both Windows 11 and Windows 10, and it works fine for the abovementioned scenarios. I also verified that the
"redirecting input/output/error to files"are still working fine, regardless of using-Credentialor not.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.