From 20a0ba041ca7e588657538ccfd6351ea81b8c150 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Mon, 21 Nov 2016 16:02:52 -0800 Subject: [PATCH] Fix the indicator for redirecting standard input (#2749) --- .../engine/NativeCommandProcessor.cs | 2 +- src/System.Management.Automation/engine/pipeline.cs | 2 +- .../NativeExecution/NativeLinuxCommands.Tests.ps1 | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/NativeCommandProcessor.cs b/src/System.Management.Automation/engine/NativeCommandProcessor.cs index 937134ad56..f572e5a686 100644 --- a/src/System.Management.Automation/engine/NativeCommandProcessor.cs +++ b/src/System.Management.Automation/engine/NativeCommandProcessor.cs @@ -1186,7 +1186,7 @@ namespace System.Management.Automation /// private void CalculateIORedirection(out bool redirectOutput, out bool redirectError, out bool redirectInput) { - redirectInput = this.Command.MyInvocation.PipelinePosition > 0; + redirectInput = this.Command.MyInvocation.ExpectingInput; redirectOutput = true; redirectError = true; diff --git a/src/System.Management.Automation/engine/pipeline.cs b/src/System.Management.Automation/engine/pipeline.cs index a6bda4a0e8..dba620bbba 100644 --- a/src/System.Management.Automation/engine/pipeline.cs +++ b/src/System.Management.Automation/engine/pipeline.cs @@ -1026,8 +1026,8 @@ namespace System.Management.Automation.Internal myInfo.PipelinePosition = i + 1; myInfo.PipelineLength = _commands.Count; myInfo.PipelineIterationInfo = pipelineIterationInfo; - commandProcessor.DoPrepare(psDefaultParameterValues); myInfo.ExpectingInput = commandProcessor.IsPipelineInputExpected(); + commandProcessor.DoPrepare(psDefaultParameterValues); } // Clear ErrorVariable as appropriate diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 index a8a38ab6d5..d7203ec277 100644 --- a/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 +++ b/test/powershell/Language/Scripting/NativeExecution/NativeLinuxCommands.Tests.ps1 @@ -15,6 +15,18 @@ Describe "NativeLinuxCommands" -tags "CI" { It "Should find Application touch" -Skip:$IsWindows { (get-command touch).CommandType | Should Be Application } + + It "Should not redirect standard input if native command is the first command in pipeline (1)" -Skip:$IsWindows { + stty | ForEach-Object -Begin { $out = @() } -Process { $out += $_ } + $out.Length -gt 0 | Should Be $true + $out[0] -like "speed * baud; line =*" | Should Be $true + } + + It "Should not redirect standard input if native command is the first command in pipeline (2)" -Skip:$IsWindows { + $out = stty + $out.Length -gt 0 | Should Be $true + $out[0] -like "speed * baud; line =*" | Should Be $true + } } Describe "Scripts with extensions" -tags "CI" {