From 09cc4decae77295216631003764ba0dbe867edf6 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Thu, 13 Apr 2017 16:54:45 -0700 Subject: [PATCH] On Unix, it is a convention for shells to accept `-i` for an interactive shell and many tools expect this behavior (`script` for example, and when setting powershell as the default shell) and calls the shell with the `-i` switch. This change is breaking in that `-i` previously could be used as short hand to match `-inputformat` which now will need to be `-in`. --- .../host/msh/CommandLineParameterParser.cs | 6 +++++- .../resources/ManagedEntranceStrings.resx | 5 ++++- test/powershell/Host/ConsoleHost.Tests.ps1 | 9 +++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index a7931e7d4cf..ba4ca508a4c 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -570,6 +570,10 @@ private void ParseHelper(string[] args) { _sshServerMode = true; } + else if (MatchSwitch(switchKey, "interactive", "i")) + { + _noInteractive = false; + } else if (MatchSwitch(switchKey, "configurationname", "config")) { ++i; @@ -801,7 +805,7 @@ private void ParseHelper(string[] args) { ParseFormat(args, ref i, ref _outFormat, CommandLineParameterParserStrings.MissingOutputFormatParameter); } - else if (MatchSwitch(switchKey, "inputformat", "i") || MatchSwitch(switchKey, "if", "i")) + else if (MatchSwitch(switchKey, "inputformat", "in") || MatchSwitch(switchKey, "if", "if")) { ParseFormat(args, ref i, ref _inFormat, CommandLineParameterParserStrings.MissingInputFormatParameter); } diff --git a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx index bf3549e4079..4ae453d4936 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx +++ b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx @@ -127,7 +127,7 @@ Copyright (C) Microsoft Corporation. All rights reserved. PowerShell[.exe] [-PSConsoleFile <file> | -Version <version>] - [-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive] + [-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive] [-Interactive] [-InputFormat {Text | XML}] [-OutputFormat {Text | XML}] [-WindowStyle <style>] [-EncodedCommand <Base64EncodedCommand>] [-ConfigurationName <string>] @@ -164,6 +164,9 @@ PowerShell[.exe] -Help | -? | /? -NonInteractive Does not present an interactive prompt to the user. +-Interactive + Present an interactive prompt to the user. + -InputFormat Describes the format of data sent to Windows PowerShell. Valid values are "Text" (text strings) or "XML" (serialized CLIXML format). diff --git a/test/powershell/Host/ConsoleHost.Tests.ps1 b/test/powershell/Host/ConsoleHost.Tests.ps1 index aafb0b2649f..50dd8fb17df 100644 --- a/test/powershell/Host/ConsoleHost.Tests.ps1 +++ b/test/powershell/Host/ConsoleHost.Tests.ps1 @@ -267,8 +267,13 @@ Describe "ConsoleHost unit tests" -tags "Feature" { # All of the following tests replace the prompt (either via an initial command or interactively) # so that we can read StandardOutput and reliably know exactly what the prompt is. - It "Interactive redirected input" { - $si = NewProcessStartInfo "-noprofile -nologo" -RedirectStdIn + It "Interactive redirected input" -TestCases @( + @{InteractiveSwitch = ""} + @{InteractiveSwitch = " -IntERactive"} + @{InteractiveSwitch = " -i"} + ) { + param($interactiveSwitch) + $si = NewProcessStartInfo "-noprofile -nologo$interactiveSwitch" -RedirectStdIn $process = RunPowerShell $si $process.StandardInput.Write("`$function:prompt = { 'PS> ' }`n") $null = $process.StandardOutput.ReadLine()