Make Windows Run a File with a Shebang on Double-Click?

Is there any shell extension for Explorer that would execute text files with a #! shebang at the beginning?


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