mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix Switch-Process to set termios appropriate for child process (#18467)
This commit is contained in:
@@ -69,10 +69,12 @@ namespace Microsoft.PowerShell.Commands
|
||||
// need null terminator at end
|
||||
execArgs[execArgs.Length - 1] = null;
|
||||
|
||||
// setup termios for a child process as .NET modifies termios dynamically for use with ReadKey()
|
||||
ConfigureTerminalForChildProcess(true);
|
||||
int exitCode = Exec(command.Source, execArgs);
|
||||
|
||||
if (exitCode < 0)
|
||||
{
|
||||
ConfigureTerminalForChildProcess(false);
|
||||
ThrowTerminatingError(
|
||||
new ErrorRecord(
|
||||
new Exception(
|
||||
@@ -108,6 +110,10 @@ namespace Microsoft.PowerShell.Commands
|
||||
CharSet = CharSet.Ansi,
|
||||
SetLastError = true)]
|
||||
private static extern int Exec(string path, string?[] args);
|
||||
|
||||
// leverage .NET runtime's native library which abstracts the need to handle different OS and architectures for termios api
|
||||
[DllImport("libSystem.Native", EntryPoint = "SystemNative_ConfigureTerminalForChildProcess")]
|
||||
private static extern void ConfigureTerminalForChildProcess([MarshalAs(UnmanagedType.Bool)] bool childUsesTerminal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user