Skip to content

ensure running powershell within PowerShell starts instance of currently running PowerShell - #4481

Merged
Dongbo Wang (daxian-dbw) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:powershell-path
Aug 4, 2017
Merged

ensure running powershell within PowerShell starts instance of currently running PowerShell#4481
Dongbo Wang (daxian-dbw) merged 2 commits into
PowerShell:masterfrom
SteveL-MSFT:powershell-path

Conversation

@SteveL-MSFT

Copy link
Copy Markdown
Member

modify PATH env var at startup so that $PSHOME is in front

Fix #4194

…ently running PowerShell

modify PATH env var at startup so that $PSHOME is in front
if (!Platform.IsWindows)
{
pathSeparator = ":";
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Path.PathSeparator.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

pathSeparator = ":";
}
string pshome = Utils.DefaultPowerShellAppBase;
path.Replace(pathSeparator + pshome, "");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the PWD got appended to the end of PATH so I didn't want it on both ends, looks like that isn't the case. I'll remove.

}
string pshome = Utils.DefaultPowerShellAppBase;
path.Replace(pathSeparator + pshome, "");
path.Insert(0, pshome + pathSeparator);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should check if the first path in $env:PATH is pshome, and only insert if it's not. Otherwise, the nested powershell instance will have 2 pshome paths in $env:PATH

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@daxian-dbw Dongbo Wang (daxian-dbw) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@daxian-dbw
Dongbo Wang (daxian-dbw) merged commit d17aaad into PowerShell:master Aug 4, 2017
}
#endif

// put PSHOME in front of PATH so that calling `powershell` within `powershell` always starts the same running version

@iSazonov Ilya (iSazonov) Aug 6, 2017

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Is this right for other applications?
  2. I would prefer more deterministic [System.Diagnostics.Process]::GetCurrentProcess().MainModule.FileName. (Related Improve experience for side-by-side versions of PowerShell #4199 . What about Start-PowerShell cmdlet?)

@SteveL-MSFT
Steve Lee (SteveL-MSFT) deleted the powershell-path branch August 6, 2017 20:03
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
…ently running PowerShell (PowerShell#4481)

Modify PATH env var at startup so that $PSHOME is in front
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants