mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Accept -i for an interactive shell (#3558)
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`.
This commit is contained in:
@@ -570,6 +570,10 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
_sshServerMode = true;
|
||||
}
|
||||
else if (MatchSwitch(switchKey, "interactive", "i"))
|
||||
{
|
||||
_noInteractive = false;
|
||||
}
|
||||
else if (MatchSwitch(switchKey, "configurationname", "config"))
|
||||
{
|
||||
++i;
|
||||
@@ -801,7 +805,7 @@ namespace Microsoft.PowerShell
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ Copyright (C) Microsoft Corporation. All rights reserved.</value>
|
||||
</data>
|
||||
<data name="ShellHelp" xml:space="preserve">
|
||||
<value>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).
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user