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
Nushell no longer respects file associations on Windows #6440
〉x.py--helpError:nu::shell::external_command (link)
×Externalcommandfailed╭─[entry#4:1:1]1│x.py--help·──┬─·╰──didyoumean'cp'?╰────help:programnotfound〉./x.py--helpError:nu::shell::external_command (link)
×Externalcommandfailed╭─[entry#5:1:1]1│./x.py--help·───┬──·╰──can't run executable ╰──── help: %1 is not a valid Win32 application. (os error 193)
Expected behavior
The file should be run using the file association. This is what happened when running via a cmd /c host shell for execution.
Hmm. My thinking is that running foo in Nushell means "attempt to run a command or executable named foo", not "open foo as if it was double-clicked in Explorer." If you need to do the later, start (i.e. start x.py) works for that.
I'm open to other points of view, but I think the new behaviour is correct.
Counterpoint: pwsh launches scripts in this manner. At the very least, even if nushell doesn't use the Windows filetype associations, it probably should have some functionality to allow running scripts without specifying the interpreter explicitly.
If nushell respects shebang lines on unix, imho it should respect file associations on Windows, which is roughly the equivalent feature.
I think I'm coming around to your point of view. Would be nice if ./x.py and .\x.py worked the way they do in PowerShell - I'll see if I can make that happen.
I bet it's #6278; if which is finding the file, then IIUC it'll get run through cmd which will do the dispatch to the associated interpreter.
I'd need to step the procedure to be sure, though. (The "is same name" check will be false because ./x.py != x.py, as it's comparing the command name to the resolved file name.)
I’m trying to understand whether you manually tested Nushell before+after that commit, or if you’re drawing conclusions based on a reading of the code/PR.
Oh, sorry; I'm drawing conclusions from reading the code that launches the executable and observing behavior; I haven't specifically tested that it was that change, but it's the only one that touched the extern dispatch, so it kind of has to be it.
So we're kindof both right, in that it is the which path executing it, but that the behavior changed after that PR when updating the dependency.
That said, the "proper" behavior is probably to
Determine the file to execute by checking the given path and the given path with exts from PATHEXT (what which is doing)
Determine how to run the file (assoc/ftype) similarly to how pwsh/cmd do; this does use the registry file associations (even in cmd!) and not the legacy ones visible through assoc/ftype. For example, try "running" a .html in cmd; ftype says iexplore.exe but it will be your actual browser choice.
The point is to "act like a shell" in terms of executing files; matching the behavior of cmd and pwsh in launching files is probably better than being "pure" and only launching directly-executables or PATHEXT executables.
Did a bit of research. pwsh use{s|d}ShellExecuteEx to launch documents (their name for files which aren't directly executable). This means that if you do ./test.py in pwsh, it'll open in a new window! (I could've sworn it wasn't that way previously...)
I also wrote a bit of code to read the file type associations, which appears to be working, but it's a huge tail of edge cases. It might be better to just use ShellExecuteEx on windows, with the SEE_MASK_NO_CONSOLE flag to inherit the parent's console. Using ShellExecuteEx also allows us to easily tell the difference between opening the file failing (returns FALSE; check GetLastError) and the process failing (outptr process handle).
I'm kinda leaning toward leaving things as-is, since the desired Python functionality works as expected. Are there specific cases you'd like to behave differently?
Did a bit of research. PowerShell/PowerShell#4523ShellExecuteEx to launch documents (their name for files which aren't directly executable). This means that if you do ./test.py in pwsh, it'll open in a new window! (I could've sworn it wasn't that way previously...)
Sorry to comment on an old and closed issue, but this is not the case for me. If you have .py in your PATHEXT environment variable, it does run the command in the same console window - I've tested this in both Powershell (powershell.exe) and Powershell Core (pwsh.exe). Without the PATHEXT setting, it does open a new window as you describe.
This is a really useful bit of functionality, which I'd like to have available (in some form - it doesn't have to be via the PATHEXT mechanism) in nushell.
Activity
rgwood commentedon Aug 29, 2022
Hmm. My thinking is that running
fooin Nushell means "attempt to run a command or executable namedfoo", not "openfooas if it was double-clicked in Explorer." If you need to do the later,start(i.e.start x.py) works for that.I'm open to other points of view, but I think the new behaviour is correct.
CAD97 commentedon Aug 29, 2022
Counterpoint: pwsh launches scripts in this manner. At the very least, even if nushell doesn't use the Windows filetype associations, it probably should have some functionality to allow running scripts without specifying the interpreter explicitly.
If nushell respects shebang lines on unix, imho it should respect file associations on Windows, which is roughly the equivalent feature.
CAD97 commentedon Aug 29, 2022
Also of note;
./x.pyshould run the script in the same terminal;start x.pyopens it in a new terminal window.rgwood commentedon Aug 29, 2022
I think I'm coming around to your point of view. Would be nice if
./x.pyand.\x.pyworked the way they do in PowerShell - I'll see if I can make that happen.rgwood commentedon Sep 5, 2022
@CAD97 I might be busy with job stuff for a little while. Are you interested in picking this up (design and/or implementation)?
rgwood commentedon Sep 7, 2022
I just gave this a try, and it works for me on Windows 11. I'm running

mainfrom ~4 days ago.Nu Version
CAD97 commentedon Sep 7, 2022
...huh, I wonder what changed. It's working for me as well now, with
I guess I'll close this, then.
CAD97 commentedon Sep 7, 2022
I bet it's #6278; if
whichis finding the file, then IIUC it'll get run through cmd which will do the dispatch to the associated interpreter.I'd need to step the procedure to be sure, though. (The "is same name" check will be false because
./x.py!=x.py, as it's comparing the command name to the resolved file name.)CAD97 commentedon Sep 7, 2022
Confirmed
rgwood commentedon Sep 7, 2022
Interesting. I wouldn't expect #6278 to fix this; you're sure it was that commit?
CAD97 commentedon Sep 7, 2022
It's definitely an accidental "fix". What's happening is roughly
and the
ifis taken since./x.py != x.pyrgwood commentedon Sep 7, 2022
Did you confirm that #6278 is the change that fixed this?
rgwood commentedon Sep 7, 2022
I’m trying to understand whether you manually tested Nushell before+after that commit, or if you’re drawing conclusions based on a reading of the code/PR.
CAD97 commentedon Sep 7, 2022
Oh, sorry; I'm drawing conclusions from reading the code that launches the executable and observing behavior; I haven't specifically tested that it was that change, but it's the only one that touched the extern dispatch, so it kind of has to be it.
rgwood commentedon Sep 7, 2022
I did the bisect, and it's not that change. It's the
which-rsupgrade from v4.2.2 to v4.3.0:I think this PR is the one that changed it: harryfei/which-rs#57
CAD97 commentedon Sep 7, 2022
So we're kindof both right, in that it is the which path executing it, but that the behavior changed after that PR when updating the dependency.
That said, the "proper" behavior is probably to
assoc/ftype. For example, try "running" a.htmlin cmd;ftypesaysiexplore.exebut it will be your actual browser choice.The point is to "act like a shell" in terms of executing files; matching the behavior of cmd and pwsh in launching files is probably better than being "pure" and only launching directly-executables or PATHEXT executables.
CAD97 commentedon Sep 8, 2022
Did a bit of research. pwsh use{s|d}
ShellExecuteExto launch documents (their name for files which aren't directly executable). This means that if you do./test.pyin pwsh, it'll open in a new window! (I could've sworn it wasn't that way previously...)I also wrote a bit of code to read the file type associations, which appears to be working, but it's a huge tail of edge cases. It might be better to just use
ShellExecuteExon windows, with theSEE_MASK_NO_CONSOLEflag to inherit the parent's console. UsingShellExecuteExalso allows us to easily tell the difference between opening the file failing (returnsFALSE; checkGetLastError) and the process failing (outptr process handle).rgwood commentedon Sep 8, 2022
Nice, thanks for the research.
I'm kinda leaning toward leaving things as-is, since the desired Python functionality works as expected. Are there specific cases you'd like to behave differently?
PJB3005 commentedon Jul 8, 2023
Sorry if I should open a new issue for this, but this still seems broken if the Python script you're trying to run isn't in the current directory:
pfmoore commentedon Dec 28, 2024
Sorry to comment on an old and closed issue, but this is not the case for me. If you have
.pyin yourPATHEXTenvironment variable, it does run the command in the same console window - I've tested this in both Powershell (powershell.exe) and Powershell Core (pwsh.exe). Without thePATHEXTsetting, it does open a new window as you describe.pfmoore commentedon Dec 28, 2024
This is a really useful bit of functionality, which I'd like to have available (in some form - it doesn't have to be via the
PATHEXTmechanism) in nushell.Run scripts of any file extension in PATHEXT on Windows (#15611)
fix running file-associated scripts with `./` paths on Windows (#19584)…