elves / elvish

Powerful scripting language & versatile interactive shell
https://elv.sh/
BSD 2-Clause "Simplified" License
5.57k stars 297 forks source link

Executable resolution on Windows has problems #1405

Open krader1961 opened 2 years ago

krader1961 commented 2 years ago

This issue is to remind me (or someone else) that there are quirks that need to be fixed regarding external command resolution on MS Windows. I made some upgrades to my Windows 10 system recently, including the Elvish version, which broke something that used to work.

The following interactive session capture shows several problems. Such as ANSI escape sequences being shown rather than acted on. For the purposes of this issue the problem is that an Elvish binary named elvish (no extension) is not recognized unless an explicit period is appended to the command name. That is elvish. works while elvish does not but only if an absolute path is used. A bare command that relies on resolution via the $paths list does not work the same way.

~\projects\3rd-party\elvish> pprint $paths
[
 C:\Users\krade\bin
 C:\msys64\usr\bin
 C:\msys64\usr\local\bin
 'C:\Program Files\Go\bin'
 C:\Users\krade\AppData\Local
 C:\WINDOWS
 C:\WINDOWS\system32
 C:\WINDOWS\system32\Wbem
 C:\WINDOWS\system32\WindowsPowerShell\v1.0
 C:\WINDOWS\system32\OpenSSH
 C:\WINDOWS\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps
 C:\msys64\Microsoft\WindowsApps
]
~\projects\3rd-party\elvish> c:\msys64\usr\local\bin/elvish
Exception: ←[31;1mexec: "c:\\msys64\\usr\\local\\bin/elvish": file does not exist←[m
[tty 32], line 1: ←[1;4mc:\msys64\usr\local\bin/elvish←[m
~\projects\3rd-party\elvish> ls -l c:\msys64\usr\local\bin
total 21384
-rwxr-xr-x 1 krader None  9683456 Sep  6 20:55 elvish
-rwxr-xr-x 1 krader None 12206592 Aug 10 21:01 elvish.old
~\projects\3rd-party\elvish> c:\msys64\usr\local\bin\elvish.
Cannot connect to daemon: unexpected RPC error on socket C:\msys64\tmp\elvish-krader\sock: dial tcp.
Daemon-related functions will likely not work.
~\projects\3rd-party\elvish>
~\projects\3rd-party\elvish> elvish.
Exception: ←[31;1mfork/exec elvish.: %1 is not a valid Win32 application.←[m
[tty 35], line 1: ←[1;4melvish.←[m
krader1961 commented 2 years ago

I should point out that installing the Elvish binary as c:\msys64\usr\local\bin\elvish.exe "fixes" the problem but it seems to me that a) shouldn't be necessary and b) if it is necessary then executing c:\msys64\usr\local\bin\elvish. should not work if a binary with that name without an explicit exe extension exists.