Use shebang/hashbang in Windows Command Prompt Use shebang/hashbang in Windows Command Prompt shell shell

Use shebang/hashbang in Windows Command Prompt


Yes, this is possible using the PATHEXT environment variable. Which is e.g. also used to register .vbs or .wsh scripts to be run "directly".

First you need to extend the PATHEXT variable to contain the extension of that serve script (in the following I assume that extension is .foo as I don't know Node.js)

The default values are something like this:

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

You need to change it (through the Control Panel) to look like this:

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.FOO

Using the control panel (Control Panel -> System -> Advanced System Settings -> Environment Variables is necessary to persist the value of the PATHEXT variable.

Then you need to register the correct "interpreter" with that extension using the commands FTYPE and ASSOC:

ASSOC .foo=FooScriptFTYPE FooScript=foorunner.exe %1 %*

(The above example is shamelessly taken from the help provided by ftype /?.)

ASSOC and FTYPE will write directly into the registry, so you will need an administrative account to run them.


Actually looks like someone who knows how to write batch files better than I has also approached this. Their batch file may work better.

http://whitescreen.nicolaas.net/programming/windows-shebangs


No, there's no way to "force" the command prompt to do this.

Windows simply wasn't designed like Unix/Linux.

Is there a shell extension that does something similar?

Not that I've heard of, but that should be asked on Super User, not here.