Ensure running powershell within PowerShell starts instance of currently running PowerShell (#4481)

Modify PATH env var at startup so that $PSHOME is in front
This commit is contained in:
Steve Lee
2017-08-04 09:23:15 -07:00
committed by Dongbo Wang
parent 5cd0e85d12
commit d17aaad4a0
2 changed files with 14 additions and 0 deletions
@@ -134,6 +134,14 @@ namespace Microsoft.PowerShell
}
#endif
// put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version
string path = Environment.GetEnvironmentVariable("PATH");
string pshome = Utils.DefaultPowerShellAppBase;
if (!path.Contains(pshome))
{
Environment.SetEnvironmentVariable("PATH", pshome + Path.PathSeparator + path);
}
try
{
string profileDir;
@@ -486,6 +486,12 @@ foo
bash -c "unset HOME;$powershell -c '1+1'" | Should BeExactly 2
}
}
Context "PATH environment variable" {
It "`$PSHOME should be in front so that powershell.exe starts current running PowerShell" {
powershell -v | Should Match $psversiontable.GitCommitId
}
}
}
Describe "Console host api tests" -Tag CI {