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
28 changes: 28 additions & 0 deletions src/System.Management.Automation/engine/AutomationEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ internal class AutomationEngine
/// </summary>
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();
Expand Down
6 changes: 6 additions & 0 deletions test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -564,3 +564,9 @@ Describe "Verify approved aliases list" -Tags "CI" {
$result | Should -BeNullOrEmpty
}
}

Describe "PATHEXT defaults" -Tags 'CI' {
It "PATHEXT contains .CPL" -Skip:(!$IsWindows) {
$env:PATHEXT.Split(";") | Should -Contain ".CPL"
}
}