From 83696c3c52df7ebfdb8d15328da85a38eba309d5 Mon Sep 17 00:00:00 2001 From: "Steve Lee (POWERSHELL)" Date: Wed, 5 Jun 2019 07:21:00 -0700 Subject: [PATCH 1/2] .CPL should be added to PATHEXT --- .../engine/AutomationEngine.cs | 28 +++++++++++++++++++ .../engine/Basic/DefaultCommands.Tests.ps1 | 6 ++++ 2 files changed, 34 insertions(+) diff --git a/src/System.Management.Automation/engine/AutomationEngine.cs b/src/System.Management.Automation/engine/AutomationEngine.cs index 72898d03939..b1e8e6ef889 100644 --- a/src/System.Management.Automation/engine/AutomationEngine.cs +++ b/src/System.Management.Automation/engine/AutomationEngine.cs @@ -35,6 +35,34 @@ internal class AutomationEngine /// internal AutomationEngine(PSHost hostInterface, InitialSessionState iss) { +#if !UNIX + // Update the env variable PathEXT to contain .CPL + var pathext = Environment.GetEnvironmentVariable("PathEXT"); + pathext = pathext ?? string.Empty; + bool cplExist = false; + if (pathext != string.Empty) + { + string[] entries = pathext.Split(Utils.Separators.Semicolon); + foreach (string entry in entries) + { + string ext = entry.Trim(); + if (ext.Equals(".CPL", StringComparison.OrdinalIgnoreCase)) + { + cplExist = true; + break; + } + } + } + + if (!cplExist) + { + pathext = (pathext == string.Empty) ? ".CPL" : + pathext.EndsWith(";", StringComparison.OrdinalIgnoreCase) + ? (pathext + ".CPL") : (pathext + ";.CPL"); + Environment.SetEnvironmentVariable("PathEXT", pathext); + } +#endif + Context = new ExecutionContext(this, hostInterface, iss); EngineParser = new Language.Parser(); diff --git a/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 b/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 index 750ecfbd518..74eeeff166a 100644 --- a/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 +++ b/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 @@ -564,3 +564,9 @@ Describe "Verify approved aliases list" -Tags "CI" { $result | Should -BeNullOrEmpty } } + +Describe "PATHEXT defaults" { + It "PATHEXT contains .CPL" -Skip:(!$IsWindows) { + $env:PATHEXT.Split(";") | Should -Contain ".CPL" + } +} From a7ee3187fd76ea4ddd19772d449d22469f00a9ec Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 5 Jun 2019 09:34:29 -0700 Subject: [PATCH 2/2] Fix build failure --- test/powershell/engine/Basic/DefaultCommands.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 b/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 index 74eeeff166a..bfe35cc4c83 100644 --- a/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 +++ b/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 @@ -565,7 +565,7 @@ Describe "Verify approved aliases list" -Tags "CI" { } } -Describe "PATHEXT defaults" { +Describe "PATHEXT defaults" -Tags 'CI' { It "PATHEXT contains .CPL" -Skip:(!$IsWindows) { $env:PATHEXT.Split(";") | Should -Contain ".CPL" }