Execute Batch file in Windows Subsystem for Linux

十年热恋 提交于 2020-07-29 10:04:19

问题


Is it possible to execute a .bat file from a Windows Subsystem for Linux (eg. Ubuntu)?

It is trivial to run an .exe file from a WSL, but I haven't found a trivial way to run a .bat. The only way I found is to open cmd.exe, but that is a bit cumbersome to do every time I need to execute a .bat file.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/48582952/execute-batch-file-in-windows-subsystem-for-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!