You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PowerShell installed as a .NET global tool cannot invoke its own CLI on macOS #12205
When PowerShell is installed as a .NET global tool, it prepends its own $PSHOME folder to $env:PATH.
However, on macOS $PSHOME contains an incompatiblepwsh binary that is for Linux.
Therefore, from within an existing session, invoking pwsh (by mere file name) unexpectedly fails.
Steps to reproduce
# Install PowerShell as a .NET global tool, to ~/.dotnet/tools
dotnet tool install powershell -g
# Invoke it, and try to re-invoke its own CLI.
~/.dotnet/tools/pwsh -noprofile -c 'pwsh -noprofile -c write-output hi'| Should -Be 'hi'
Expected behavior
The test should succeed.
Actual behavior
The test fails, due to incompatible binary being invoked:
Expected 'hi', but got @('ResourceUnavailable: Program 'pwsh' failed to run: Exec format errorAt line:1 char:1' ...
this is still a problem on macOS 11.1 and it can be quite unpleasant when deploying xplat scripts. I would expect that invoking a child pwsh would work under every circumstance
Steven Bucher (@StevenBucher98): Thanks for connecting the dots. Yep, looks like the same bug to me. Knowing about #11141 explains why changing $PATH didn't fix the problem for me. The workaround I mentioned in my bug is very simple:
cd $PSHOME
mv pwsh pwsh.elf
ln -s ../../../../../../../../../../../.dotnet/tools/pwsh pwsh
It fixes this bug as well, unsurprisingly. I've been running in this state since I posted my bug and have yet to notice any adverse effects.
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
Activity
mklement0 commentedon Mar 26, 2020
TravisEz13 commentedon Apr 7, 2020
I verified this behavior on 7.0.0 on macOS 10.15.4
albigi commentedon Dec 30, 2020
this is still a problem on macOS 11.1 and it can be quite unpleasant when deploying xplat scripts. I would expect that invoking a child pwsh would work under every circumstance
kkshinkai commentedon Jul 28, 2021
Any progress on this?
#11141 puts
$PSHOMEat the front of$PATH, so this problem becomes unsolvable under macOS. Perhaps we should put$PSHOMEat the end of the$PATH.ins0mniaque commentedon Mar 13, 2022
This is still a problem on macOS 12.2.1 (arm64).
I can confirm that having $PSHOME in front of $PATH (#11141) makes it impossible to fix using $Env:Path under macOS.
As a workaround, I added this to my PowerShell profile:
StevenBucher98 commentedon Sep 26, 2022
Looks like possibly another issue reported around this bug, #18139
dlnash18 commentedon Oct 7, 2022
Steven Bucher (@StevenBucher98): Thanks for connecting the dots. Yep, looks like the same bug to me. Knowing about #11141 explains why changing $PATH didn't fix the problem for me. The workaround I mentioned in my bug is very simple:
It fixes this bug as well, unsurprisingly. I've been running in this state since I posted my bug and have yet to notice any adverse effects.
lukket commentedon Jun 12, 2023
It's now 2023, macOS 13.4, PowerShell 7.3.4 and this is still an issue...
Thanks for the workaround Donald Nash (@dlnash18).
microsoft-github-policy-service commentedon Dec 9, 2023
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.