在Windows Subsystem for Linux中执行批处理文件 [英] Execute Batch file in Windows Subsystem for Linux

查看:96
本文介绍了在Windows Subsystem for Linux中执行批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从Windows子系统(例如Ubuntu)执行.bat文件?

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

从WSL运行.exe文件很简单,但是我还没有找到运行.bat的简单方法.我发现的唯一方法是打开cmd.exe,但是每次我需要执行.bat文件时,这样做都会很麻烦.

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.

推荐答案

不幸的是,目前您不使用以下任何一种方法都无法这样做:

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

cmd.exe /c foo.bat

…或以下使用binfmt的骇客:

…or the following hack using binfmt:

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

然后您可以输入:

foo.bat

此方法的问题是您需要是root用户,每次打开bash窗口时都要运行它,可能也对.cmd文件执行相同的操作,我想,任何bash脚本名称以.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!

我猜想,直到Microsoft处理此问题为止,您仅限于上述情况.

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

这篇关于在Windows Subsystem for Linux中执行批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆