question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch-Process, when used to replace the PowerShell process with an interactive (different) shell session, breaks that session

See original GitHub issue

Prerequisites

Steps to reproduce

Clearly not a common use case, but a bug nonetheless:

When you use Switch-Process (exec) to replace the current PowerShell process (running an interactive session) with a different shell’s interactive session (e.g., bash), that session’s command-line editing is broken.

# Run on macOS or Linux
Switch-Process /bin/bash

Expected behavior

A regular interactive Bash session.

Actual behavior

What the user types on the Bash command line doesn’t print (however, submitting commands and printing output works normally).

Error details

No response

Environment data

PowerShell Core 7.3.0-rc.1 on macOS 12.6 or Linux

Visuals

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
daxian-dbwcommented, Nov 3, 2022

Instead of PowerShell, It could be what .NET does, or more specifically, what [Console]::Readkey does. The following is quoted from the blog about “Console.ReadKey” improvement:

tcsetattr allows for changing the terminal settings. It’s used by .NET to apply its own setting at startup, and restore the previous settings at rundown.

1reaction
SteveL-MSFTcommented, Nov 3, 2022

I’m guessing that fish, zsh, etc… is explicitly setting stty to echo whereas older shells do not. Don’t understand what other shells are doing to make it work. Here’s something that’s a bit interesting:

PS> stty
speed 38400 baud;
lflags: echoe echok echoke echoctl pendin
iflags: iutf8
oflags: -oxtabs
cflags: cs8 -parenb
[61.39ms] /Users/steve
PS> pwsh -c { exec stty }
speed 38400 baud;
lflags: echoe echok echoke echoctl pendin
iflags: iutf8
oflags: -oxtabs
cflags: cs8 -parenb
[318.76ms] /Users/steve
PS> pwsh
PowerShell 7.3.0-rc.1
/Users/steve
PS> exec stty
speed 38400 baud;
lflags: -icanon -iexten -echo echoe echok echoke echoctl pendin
iflags: -icrnl -ixon iutf8
oflags: -oxtabs
cflags: cs8 -parenb

So interactive mode for PowerShell is doing something affecting the tty.

Read more comments on GitHub >

github_iconTop Results From Across the Web

about Remote Disconnected Sessions - PowerShell
Explains how to disconnect and reconnect to a PowerShell Session (PSSession).
Read more >
Exit-PSSession (Microsoft.PowerShell.Core)
The Exit-PSSession cmdlet ends interactive sessions that you started by using the Enter-PSSession cmdlet. You can also use the exit keyword to end...
Read more >
Enter-PSHostProcess (Microsoft.PowerShell.Core)
The Enter-PSHostProcess cmdlet connects to and enters into an interactive session with a local process. Beginning in PowerShell 6.2, this cmdlet is ...
Read more >
Resolving PowerShell module assembly dependency ...
This presents issues when a module's dependencies conflict with already-loaded DLLs and may prevent using two otherwise unrelated modules in the ...
Read more >
Differences between Windows PowerShell 5.1 and ...
This article summarizes the differences and breaking changes from Windows PowerShell 5.1 and the current version of PowerShell that is based ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found