Leave the input/output/error handles unset when they are not redirected by daxian-dbw · Pull Request #20853 · PowerShell/PowerShell
PR Summary
This PR is to fix Start-Process to address PowerShell/PSReadLine#288.
Basically, when starting pwsh with Start-Process in the following ways, the new console and the existing console get weirdly tied together, which causes Console.ReadKey running 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.cs is related. When running Start-Process pwsh -Credential as a non-admin user, the "TaskbarJumpList" code throws AccessDenied exception, which causes a debug build to crash. The Debug.Fail is not needed. The catch (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 -Credential or not.
PR Checklist
- PR has a meaningful title
- Use the present tense and imperative mood when describing your changes
- Summarized changes
- Make sure all
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header - This PR is ready to merge and is not Work in Progress.
- If the PR is work in progress, please add the prefix
WIP: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.
- If the PR is work in progress, please add the prefix
- Breaking changes
- None
- OR
- Experimental feature(s) needed
- Experimental feature name(s):
- User-facing changes
- Not Applicable
- OR
- Documentation needed
- Issue filed:
- Testing - New and feature
- N/A or can only be tested interactively
- OR
- Make sure you've added a new test if existing tests do not effectively test the code changed
- Tooling
- I have considered the user experience from a tooling perspective and don't believe tooling will be impacted.