Make Windows Run a File with a Shebang on Double-Click?
Solution 1
You're very much in conflict with the Microsoft model for files. In the POSIX model, the filename doesn't dictate whether a file is executable, at all. That's solely the province of the permissions. In the Microsoft model used in Windows Explorer, whether a file is executable is also determined by its filename, in particular by the extension. Hence the FTYPE
command, the ASSOC
command, the PATHEXT
environment variable, and so forth.
So, with the proviso that this is restricted to files with the .CMD
extension, in order to fit in with the aforementioned model, there actually is an extension that will pass files beginning with #!
to the script interpreter named on that line. It's JP Software's TCC, a replacement command interpreter which has both #!
and EXTPROC
support. Explorer can be told to hand off all .CMD
files to TCC, which in turn will read the #!
and hand off to the named script interpreter.
If you want to use #!
with any other file extensions in Explorer, then you hit the paradigm conflict, and you'll have to switch to using file extension associations, just like the person with the CGI script did in the article hyperlinked-to by new123456
. Extension determining script interpreter, not magic numbers in file contents, is the paradigm that Windows Explorer uses.
Solution 2
If your text file happens to by a Python File then you can do exactly what you want using pylauncher.
From the docs:
PEP 397 compatible launcher for Python under Windows. See http://www.python.org/dev/peps/pep-0397/ for PEP, http://www.red-dove.com/screencasts/launcher/la... for screencast
Related videos on Youtube
user541686
Updated on September 18, 2022Comments
-
user541686 almost 2 years
Is there any shell extension for Explorer that would execute text files with a
#!
shebang at the beginning?-
Admin about 13 yearsI don't think so. The registry only holds suffixes. I Googled around, but could not find anything.
-
Admin about 13 yearsHmm... does this work?
-
Admin about 13 yearsYou need to be more specific... What kind of executable are you tying to create? Did you change permissions to make your "Text File" executable? What shell are you trying to use (e.g. #!/bin/bash) ?
-
Admin over 8 years@chrsblck But I don’t remember Windows supporting marking things “executable”…
-
-
dragon788 almost 8 yearsAccording to their documentation you can also use it to launch arbitrary programs from the shebang, with the caveat that they must be in the system %PATH% because that's where Python searches for the application.