Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/PowerShell/PowerShell.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Lee <slee@microsoft.com>2022-11-05 01:12:09 +0300
committerGitHub <noreply@github.com>2022-11-05 01:12:09 +0300
commita2ee05400f8cb4a44cd87742f95ebc2c3472e649 (patch)
treec86407da0ce004a57c8d6433e3e0ee5607842f18
parent39756d5602546d5956d4e8d87922efa1e35f0d83 (diff)
Fix `Switch-Process` to set termios appropriate for child process (#18467)
-rw-r--r--src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs b/src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
index 5e0cee6684..5734518231 100644
--- a/src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
+++ b/src/System.Management.Automation/engine/Modules/SwitchProcessCommand.cs
@@ -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);
}
}