问题描述
随着2016年夏季的Windows 10周年更新,可以在新的Windows Subsystem for Linux (WSL)(“lightweight”虚拟化子系统)中运行ubuntu二进制文件。
不幸的是,启动C:\Windows\System32\bash.exe,另一个bash ELF二进制文件启动了WSL内部的进程,从那里你无法逃脱!您可以只启动其他ELF二进制文件。
那么如何从Windows Bash执行*.exe文件?[1]
最佳解决方法
原生解决方案
Windows 10 Insider预览更新(14951)提供的官方解决方案基于几乎被遗忘的用于启动二进制文件的binfmt_msc Linux工具。 binfmt_misc的注册命令是这样的(其中/init是win-executables的临时binfmt_misc “interpreter”):
sudo echo ":WSLInterop:M::MZ::/init:" > /proc/sys/fs/binfmt_misc/register
然后win-executable将像常规程序一样启动:
$ export PATH=$PATH:/mnt/c/Windows/System32
$ notepad.exe
$ ipconfig.exe | grep IPv4 | cut -d: -f2
$ ls -la | findstr.exe foo.txt
$ cmd.exe /c dir
Not that any win-executable must reside in the windows (DrvFs) file-system – not on the Linux’s file-system (VolFs) – in order