piotrmurach/tty-which

Fails on windows for file with custom extension

barcharcraz opened this issue · 4 comments

On windows you can run TTY::Which.which('something.py') for example and it will return false no matter if .py is in PATHEXT or not. It looks like File.executable? returns false in this case, possibly because it does not know how to deal with windows ACLs.

It looks like File.stat returns 0644 for a file such as this, even though I have the Read & Execute ACL. This may be a bug in ruby or in whatever ruby is using to translate windows ACLs into POSIX mode bits.

Thanks for using this library!

I would welcome any patches that increase compatibility of executable_file? call with Windows executables. The only observation here is that I would also consider adding the directory where something.py lives to the PATH, because this gem only searches known path directories.

I would be open to extending the which call with additional arguments that allow to dynamically specify additional directories to search through, e.i:

TTY::Which.which('ruby', 'usr/local/bin', 'usr/bin', 'bin')

The directory with 'something.py' is in my path. The issue is that the builtin File.execute? function seems to behave unexpectedly on windows.

I realized just now that the reason executable? returns false on windows is because, unlike on unix, the file association is a shell thing, not a kernel thing (ld.so will read the shabang and select the interpreter). It looks like the windows loader is actually able to load .bat and .cmd files (and some others, probably vbscript and jscript as well), directly, but for pyhton and ruby it runs through the shell even if .py and .rb are in your path.

In light of this I think tty-which's behavior may be correct.

That makes sense, Windows is not my forte, however, I'm keen for the tty libraries to work on Windows as well. Let me know if you uncover any more.