Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ internal static int MaxNameLength()
return maxLength - Path.GetTempPath().Length;
}

internal bool? TestHookConsoleInputRedirected;
internal bool? InputRedirectedTestHook;

private static readonly string[] s_validParameters = {
"sta",
Expand Down Expand Up @@ -209,6 +209,7 @@ internal CommandLineParameterParser()
}

#region Internal properties

internal bool AbortStartup
{
get
Expand Down Expand Up @@ -245,6 +246,17 @@ internal bool WasInitialCommandEncoded
}
}

#if !UNIX
internal ProcessWindowStyle? WindowStyle
{
get
{
AssertArgumentsParsed();
return _windowStyle;
}
}
#endif

internal bool ShowBanner
{
get
Expand Down Expand Up @@ -846,9 +858,7 @@ private void ParseHelper(string[] args)

try
{
ProcessWindowStyle style = (ProcessWindowStyle)LanguagePrimitives.ConvertTo(
args[i], typeof(ProcessWindowStyle), CultureInfo.InvariantCulture);
ConsoleControl.SetConsoleMode(style);
_windowStyle = LanguagePrimitives.ConvertTo<ProcessWindowStyle>(args[i]);
}
catch (PSInvalidCastException e)
{
Expand Down Expand Up @@ -1234,7 +1244,7 @@ private bool ParseCommand(string[] args, ref int i, bool noexitSeen, bool isEnco
return false;
}

if (TestHookConsoleInputRedirected.HasValue ? !TestHookConsoleInputRedirected.Value : !Console.IsInputRedirected)
if (InputRedirectedTestHook.HasValue ? !InputRedirectedTestHook.Value : !Console.IsInputRedirected)
{
SetCommandLineError(CommandLineParameterParserStrings.StdinNotRedirected, showHelp: true);
return false;
Expand Down Expand Up @@ -1340,6 +1350,7 @@ private bool CollectArgs(string[] args, ref int i)
private string? _workingDirectory;

#if !UNIX
private ProcessWindowStyle? _windowStyle;
private bool _removeWorkingDirectoryTrailingCharacter = false;
#endif
}
Expand Down
7 changes: 7 additions & 0 deletions src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ internal static void ParseCommandLine(string[] args)
{
s_cpp.Parse(args);

#if !UNIX
if (s_cpp.WindowStyle.HasValue)
{
ConsoleControl.SetConsoleMode(s_cpp.WindowStyle.Value);
}
#endif

if (s_cpp.SettingsFile is not null)
{
PowerShellConfig.Instance.SetSystemConfigFilePath(s_cpp.SettingsFile);
Expand Down
6 changes: 3 additions & 3 deletions test/xUnit/csharp/test_CommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public static void TestParameter_Command_With_Dash_And_Not_ConsoleInputRedirecte
{
var cpp = new CommandLineParameterParser();

cpp.TestHookConsoleInputRedirected = false;
cpp.InputRedirectedTestHook = false;

cpp.Parse(commandLine);

Expand Down Expand Up @@ -512,7 +512,7 @@ public static void TestParameter_Command_With_Dash_And_ConsoleInputRedirected(pa
{
var cpp = new CommandLineParameterParser();

cpp.TestHookConsoleInputRedirected = true;
cpp.InputRedirectedTestHook = true;

cpp.Parse(commandLine);

Expand Down Expand Up @@ -855,7 +855,7 @@ public static void TestParameter_EncodedCommand_With_Dash_And_ConsoleInputRedire
{
var cpp = new CommandLineParameterParser();

cpp.TestHookConsoleInputRedirected = true;
cpp.InputRedirectedTestHook = true;

cpp.Parse(commandLine);

Expand Down