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: start pwsh with its stderr redirected to the file error.txt
  • Start-Process pwsh -PassThru -Credential (Get-Credential <another-user>): start pwsh as 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