Execute Batch file in Windows Subsystem for Linux

Sorry to post on such an old thread but I found a way around it (not sure if it's something that's changed from updates, I'm posting on 18/02/2021). I found that running CMD and then feeding it arguments (to link to the requisite batch file) works - it also an accept constructed arguments sent to that command. So in my case (I'm using Debian 10.8 in WSL on 10 Pro):

/mnt/c/windows/system32/cmd.exe /mnt/c/temp/batchfile.bat "-arga -argb -argc"

I think this may be fairly consistent and workable workaround (just using C:\temp\bathfile.bat as an example, just use the relative /mnt/<drv>/<dir>/<batchfile> path for your needs).


If the first answer doesn't work, try:

sudo sh -c "echo :WindowsBatch:E::bat::/init: > /proc/sys/fs/binfmt_misc/register"

Then, locate the file. Then make the file executable:

chmod +x foo.bat

Then run the file:

./foo.bat

If it says permission denied, just try running it with sudo


Unfortunately at the moment you cannot do so without either using:

cmd.exe /c foo.bat

…or the following hack using binfmt:

sudo sh -c "echo :WindowsBatch:E::bat::/init: > /proc/sys/fs/binfmt_misc/register"

You could then just type:

foo.bat

The problems with this method are that you'd need to be root, run it each time you opened a bash window, probably do the same for .cmd files too and, I suppose, any bash script name ending with .bat could have issues!

I guess until Microsoft deals with this issue, you're limited to the above.