New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Windows executable from bash #333

Closed
ShyPixie opened this Issue May 7, 2016 · 28 comments

Comments

Projects
None yet
@ShyPixie

ShyPixie commented May 7, 2016

I'm using bash as my default console, but I cannot execute any Windows binary:

$ /mnt/c/Windows/notepad.exe
Failed to execute process '/mnt/c/Windows/notepad.exe'. Reason:
exec: Exec format error
The file '/mnt/c/Windows/notepad.exe' is marked as an executable but could not be run by the operating system.

It's not possible with lxss? It's working for me with cygwin

@bmon

This comment has been minimized.

Show comment
Hide comment
@bmon

bmon May 7, 2016

They said this functionality wouldn't be there from the start. Perhaps we'll see it at a later date, but don't hold your breath.
From this blog post (see also more discussion in the comments)

Third, note that Bash and Linux tools cannot interact with Windows applications and tools, and vice-versa. So you won’t be able to run Notepad from Bash, or run Ruby in Bash from PowerShell.

bmon commented May 7, 2016

They said this functionality wouldn't be there from the start. Perhaps we'll see it at a later date, but don't hold your breath.
From this blog post (see also more discussion in the comments)

Third, note that Bash and Linux tools cannot interact with Windows applications and tools, and vice-versa. So you won’t be able to run Notepad from Bash, or run Ruby in Bash from PowerShell.

@Artoria2e5

This comment has been minimized.

Show comment
Hide comment
@Artoria2e5

Artoria2e5 May 8, 2016

or run Ruby in Bash from PowerShell

Just an irrelevant note: bash.exe passes argv to bash, so bash -c does work.

exec: Exec format error

This reminds me of the binfmt mechanism in Linux kernel where you can define how files with all sorts of magic can be run... MS can probably use something like a broker over (uh) winsocks to bridge lxss with win32 (see cbwin). Personally I have seen Linux users setting binfmt to wine stuff on Linux automatically.

Artoria2e5 commented May 8, 2016

or run Ruby in Bash from PowerShell

Just an irrelevant note: bash.exe passes argv to bash, so bash -c does work.

exec: Exec format error

This reminds me of the binfmt mechanism in Linux kernel where you can define how files with all sorts of magic can be run... MS can probably use something like a broker over (uh) winsocks to bridge lxss with win32 (see cbwin). Personally I have seen Linux users setting binfmt to wine stuff on Linux automatically.

@LFBernardo

This comment has been minimized.

Show comment
Hide comment
@LFBernardo

LFBernardo May 8, 2016

You can for now until they build the functionality maybe use winexe. It is very powerful (like PSEXEC)

LFBernardo commented May 8, 2016

You can for now until they build the functionality maybe use winexe. It is very powerful (like PSEXEC)

@xilun

This comment has been minimized.

Show comment
Hide comment
@xilun

xilun May 8, 2016

You can also try cbwin - work in progress, but already usable.

xilun commented May 8, 2016

You can also try cbwin - work in progress, but already usable.

@rodrymbo

This comment has been minimized.

Show comment
Hide comment
@rodrymbo

rodrymbo May 10, 2016

If you can run bash -c from powershell or cmd, you are getting the "magic" bash in c:\windows\system32, the one that gets the magic emulation thing going. This is not bash from the ubuntu distro.

When it works, the magic bash -c does pass a script along through the magic emulation thingy to ubuntu's bash, but it doesn't perform any conversion on the path.

rodrymbo commented May 10, 2016

If you can run bash -c from powershell or cmd, you are getting the "magic" bash in c:\windows\system32, the one that gets the magic emulation thing going. This is not bash from the ubuntu distro.

When it works, the magic bash -c does pass a script along through the magic emulation thingy to ubuntu's bash, but it doesn't perform any conversion on the path.

@Kramax

This comment has been minimized.

Show comment
Hide comment
@Kramax

Kramax May 16, 2016

I was very much hoping I could replace cygwin with WSL. We use it extensively for doing command line builds. Unfortunately we need to use win32 compiler executables such as Intel compilers to generate win32 executables. The lack of this feature totally kills this hope. It makes what could be an alternative way of interfacing with windows into basically a (fairly well) integrated virtual machine. But in the end not that different from running a console only Ubuntu inside of a VMWare VM with file sharing.

Kramax commented May 16, 2016

I was very much hoping I could replace cygwin with WSL. We use it extensively for doing command line builds. Unfortunately we need to use win32 compiler executables such as Intel compilers to generate win32 executables. The lack of this feature totally kills this hope. It makes what could be an alternative way of interfacing with windows into basically a (fairly well) integrated virtual machine. But in the end not that different from running a console only Ubuntu inside of a VMWare VM with file sharing.

@mths0x5f

This comment has been minimized.

Show comment
Hide comment
@mths0x5f

mths0x5f May 16, 2016

@Kramax, https://github.com/xilun/cbwin by @xilun just works for now. I hope this feature will be integrated, though.

mths0x5f commented May 16, 2016

@Kramax, https://github.com/xilun/cbwin by @xilun just works for now. I hope this feature will be integrated, though.

@benhillis

This comment has been minimized.

Show comment
Hide comment
@benhillis

benhillis May 16, 2016

Member

I can't commit to timelines but I want to assure you this is absolutely on our radar.

Member

benhillis commented May 16, 2016

I can't commit to timelines but I want to assure you this is absolutely on our radar.

@aseering

This comment has been minimized.

Show comment
Hide comment
@aseering

aseering May 16, 2016

Contributor

@benhillis that's great to hear!

I've been watching the relevant UserVoice; I'm hoping its status will be updated when more information is available?

Contributor

aseering commented May 16, 2016

@benhillis that's great to hear!

I've been watching the relevant UserVoice; I'm hoping its status will be updated when more information is available?

@Kramax

This comment has been minimized.

Show comment
Hide comment
@Kramax

Kramax May 16, 2016

@mths0x5f said:

@Kramax, https://github.com/xilun/cbwin by @xilun just works for now. I hope this feature will be integrated, though.

Yes, I saw that--it is impressive. But it would require rewriting all our scripts to preface any win32 exe call with the "make call to win32 exe" command. And I think there are some security issues with having a process listen on a port to execute any executable.

Kramax commented May 16, 2016

@mths0x5f said:

@Kramax, https://github.com/xilun/cbwin by @xilun just works for now. I hope this feature will be integrated, though.

Yes, I saw that--it is impressive. But it would require rewriting all our scripts to preface any win32 exe call with the "make call to win32 exe" command. And I think there are some security issues with having a process listen on a port to execute any executable.

@mths0x5f

This comment has been minimized.

Show comment
Hide comment
@mths0x5f

mths0x5f May 16, 2016

Yes, I saw that--it is impressive. But it would require rewriting all our scripts to preface any win32 exe call with the "make call to win32 exe" command.

I'm just curious how this could be accomplished. Mixing Windows and Linux PATHs may not be a good idea... I think prefixing with a four-word-command is indispensable and not a hassle, providing a "working context" to commands like sudo does (the context of root privileges).

mths0x5f commented May 16, 2016

Yes, I saw that--it is impressive. But it would require rewriting all our scripts to preface any win32 exe call with the "make call to win32 exe" command.

I'm just curious how this could be accomplished. Mixing Windows and Linux PATHs may not be a good idea... I think prefixing with a four-word-command is indispensable and not a hassle, providing a "working context" to commands like sudo does (the context of root privileges).

@xilun

This comment has been minimized.

Show comment
Hide comment
@xilun

xilun May 16, 2016

There is the traditional heuristics based approach to try to convert parts of the context automatically -- but given what WSL does (runs unmodified "GNU" distro userspace) and how is often used the environment variables under Windows (PATH can be modified by any random program installer) I'm not 100% sure this would be a good idea by default. I don't know if other things have been tried before, in particular I don't know what was the approach in SUA (and previously in the Posix Subsystem) -- but keep in mind that all those subsystems were specific targets while the userspace run by WSL is bit for bit a binary copy of what is run under a real Linux kernel, and in general does not even know that Windows exists, so from the point of view of that environment Windows is always going to be a little bit special, whatever you attempt... Even Cygwin, which is layered above Win32, tends to depart from the let's mix everything approach it more or less had for a time in some packages (mostly only graphical stuff)

xilun commented May 16, 2016

There is the traditional heuristics based approach to try to convert parts of the context automatically -- but given what WSL does (runs unmodified "GNU" distro userspace) and how is often used the environment variables under Windows (PATH can be modified by any random program installer) I'm not 100% sure this would be a good idea by default. I don't know if other things have been tried before, in particular I don't know what was the approach in SUA (and previously in the Posix Subsystem) -- but keep in mind that all those subsystems were specific targets while the userspace run by WSL is bit for bit a binary copy of what is run under a real Linux kernel, and in general does not even know that Windows exists, so from the point of view of that environment Windows is always going to be a little bit special, whatever you attempt... Even Cygwin, which is layered above Win32, tends to depart from the let's mix everything approach it more or less had for a time in some packages (mostly only graphical stuff)

@ankostis

This comment has been minimized.

Show comment
Hide comment
@ankostis

ankostis Aug 12, 2016

Yes, I saw that--it is impressive. But it would require rewriting all our scripts to preface any win32 exe call with the "make call to win32 exe" command.

I'm just curious how this could be accomplished.

In Linux kernel there is the binfmt facility to execute ANY binary file by prefixing with its interpreter.
Maybe Microsoft can provide this last mile, and emulate the linux-module's operation of /proc/sys/fs/binfmt_misc/register path?

ankostis commented Aug 12, 2016

Yes, I saw that--it is impressive. But it would require rewriting all our scripts to preface any win32 exe call with the "make call to win32 exe" command.

I'm just curious how this could be accomplished.

In Linux kernel there is the binfmt facility to execute ANY binary file by prefixing with its interpreter.
Maybe Microsoft can provide this last mile, and emulate the linux-module's operation of /proc/sys/fs/binfmt_misc/register path?

@JakeSchieber

This comment has been minimized.

Show comment
Hide comment
@JakeSchieber

JakeSchieber Aug 23, 2016

Hey all. This was frustrating me so I created this in the meantime. I would love to hear your thoughts on it! My main annoyance was that I wanted to launch exe without typing any additional commands. This enables the pseudo execution of any exe directly from the bash cmd line without any additional keystrokes (ex: launches 'code.exe' directly by typing 'code') https://github.com/JakeSchieber/bashex

JakeSchieber commented Aug 23, 2016

Hey all. This was frustrating me so I created this in the meantime. I would love to hear your thoughts on it! My main annoyance was that I wanted to launch exe without typing any additional commands. This enables the pseudo execution of any exe directly from the bash cmd line without any additional keystrokes (ex: launches 'code.exe' directly by typing 'code') https://github.com/JakeSchieber/bashex

@chrisjbreisch

This comment has been minimized.

Show comment
Hide comment
@chrisjbreisch

chrisjbreisch Aug 23, 2016

@JakeSchieber I suppose that will work. I just use SSH. So, I have an SSH server running under windows and then a very simple shell script, cmd.sh:

#!/bin/sh
ssh localhost "$@" | dos2unix

I have another shell script pathToWinPath that converts my paths to a pathname that Windows can understand. You can just use the AppData path. I originally used SSHFS for this and a mounted drive. That might be a bit safer, but increases overhead. (It requires yet another SSH server running on the WSL side at a different port).

Anyway, you'd use both something like this:

[07:36:44] chris@CJBREISCH-SB [ ~/bin ]$ cmd.sh dir $(pathToWinPath ${PWD})
 Volume in drive U is Ubuntu
 Volume Serial Number is 01D8-EAD3

 Directory of U:\home\chris\bin

08/18/2016  10:14 AM             8,042 build-tool
08/16/2016  10:34 PM                40 cmd.sh
08/16/2016  10:34 PM                65 foo
08/19/2016  12:36 PM             1,326 get-packages.sh
08/16/2016  10:34 PM                51 pathToWinPath
08/18/2016  12:06 PM                90 runc
08/19/2016  01:12 PM               302 upgrade-release
08/16/2016  10:34 PM               165 upgrade-ubuntu
               8 File(s)         10,081 bytes
               0 Dir(s)  609,890,824,192 bytes free
[07:36:59] chris@CJBREISCH-SB [ ~/bin ]$

chrisjbreisch commented Aug 23, 2016

@JakeSchieber I suppose that will work. I just use SSH. So, I have an SSH server running under windows and then a very simple shell script, cmd.sh:

#!/bin/sh
ssh localhost "$@" | dos2unix

I have another shell script pathToWinPath that converts my paths to a pathname that Windows can understand. You can just use the AppData path. I originally used SSHFS for this and a mounted drive. That might be a bit safer, but increases overhead. (It requires yet another SSH server running on the WSL side at a different port).

Anyway, you'd use both something like this:

[07:36:44] chris@CJBREISCH-SB [ ~/bin ]$ cmd.sh dir $(pathToWinPath ${PWD})
 Volume in drive U is Ubuntu
 Volume Serial Number is 01D8-EAD3

 Directory of U:\home\chris\bin

08/18/2016  10:14 AM             8,042 build-tool
08/16/2016  10:34 PM                40 cmd.sh
08/16/2016  10:34 PM                65 foo
08/19/2016  12:36 PM             1,326 get-packages.sh
08/16/2016  10:34 PM                51 pathToWinPath
08/18/2016  12:06 PM                90 runc
08/19/2016  01:12 PM               302 upgrade-release
08/16/2016  10:34 PM               165 upgrade-ubuntu
               8 File(s)         10,081 bytes
               0 Dir(s)  609,890,824,192 bytes free
[07:36:59] chris@CJBREISCH-SB [ ~/bin ]$
@aseering

This comment has been minimized.

Show comment
Hide comment
@aseering

aseering Aug 23, 2016

Contributor

@JakeSchieber -- thanks for posting your script! It looks very useful. Could you help me understand how it differs from cbwin, though? Linked to earlier in this thread.

Contributor

aseering commented Aug 23, 2016

@JakeSchieber -- thanks for posting your script! It looks very useful. Could you help me understand how it differs from cbwin, though? Linked to earlier in this thread.

@U007D

This comment has been minimized.

Show comment
Hide comment
@U007D

U007D Aug 29, 2016

@aseering It's different because by setting up an alias for the windows .exe's you want to call, you don't have to prefix the calls you make with wcmd/wstart, etc. inside WinBash.

U007D commented Aug 29, 2016

@aseering It's different because by setting up an alias for the windows .exe's you want to call, you don't have to prefix the calls you make with wcmd/wstart, etc. inside WinBash.

@Artoria2e5

This comment has been minimized.

Show comment
Hide comment
@Artoria2e5

Artoria2e5 Aug 29, 2016

@BradleyGibson: by setting up an alias for the windows .exe

The same thing can be done with cbwin's commands, say alias dir='wcmd something'.

@aseering The difference lies in how each program is implemented. cbwin's listener process, outbash seems to run under your current login session, while cmd.sh utilizes the OpenSSH login support in Windows 10, thus another login session. Since some reports that GUI apps won't launch in Windows 10 OpenSSH cmd, this session might in fact be a "headless" one.

Artoria2e5 commented Aug 29, 2016

@BradleyGibson: by setting up an alias for the windows .exe

The same thing can be done with cbwin's commands, say alias dir='wcmd something'.

@aseering The difference lies in how each program is implemented. cbwin's listener process, outbash seems to run under your current login session, while cmd.sh utilizes the OpenSSH login support in Windows 10, thus another login session. Since some reports that GUI apps won't launch in Windows 10 OpenSSH cmd, this session might in fact be a "headless" one.

@U007D

This comment has been minimized.

Show comment
Hide comment
@U007D

U007D commented Aug 29, 2016

@Artoria2e5 good points.

@jackchammons

This comment has been minimized.

Show comment
Hide comment
@jackchammons

jackchammons Oct 24, 2016

Member

Windows <-> WSL interoperability was added in build #14951. Thanks for the feedback and patience!

Member

jackchammons commented Oct 24, 2016

Windows <-> WSL interoperability was added in build #14951. Thanks for the feedback and patience!

@tiemuer

This comment has been minimized.

Show comment
Hide comment
@tiemuer

tiemuer Dec 28, 2016

@jackchammons Any idea when this feature will be publicly available?

tiemuer commented Dec 28, 2016

@jackchammons Any idea when this feature will be publicly available?

@benhillis

This comment has been minimized.

Show comment
Hide comment
@benhillis

benhillis Dec 28, 2016

Member

@tiemuer - This change will be in the next release of Windows which is due Spring 2017.

Member

benhillis commented Dec 28, 2016

@tiemuer - This change will be in the next release of Windows which is due Spring 2017.

@vaibhav-y

This comment has been minimized.

Show comment
Hide comment
@vaibhav-y

vaibhav-y Mar 17, 2017

@benhillis When is the spring update due?

vaibhav-y commented Mar 17, 2017

@benhillis When is the spring update due?

@benhillis

This comment has been minimized.

Show comment
Hide comment
@benhillis

benhillis Mar 17, 2017

Member

@vaibhav-y - I don't think we've announced an exact date but in a month or so.

Member

benhillis commented Mar 17, 2017

@vaibhav-y - I don't think we've announced an exact date but in a month or so.

@mikeyGlitz

This comment has been minimized.

Show comment
Hide comment
@mikeyGlitz

mikeyGlitz Mar 20, 2017

I've seen news reports that Microsoft will be releasing the Creators' update on April 11th.
From what I understand, the Creators' Update will contain the fixes to run Windows programs from WSL

mikeyGlitz commented Mar 20, 2017

I've seen news reports that Microsoft will be releasing the Creators' update on April 11th.
From what I understand, the Creators' Update will contain the fixes to run Windows programs from WSL

@geerlingguy

This comment has been minimized.

Show comment
Hide comment
@geerlingguy

geerlingguy Apr 7, 2017

Note that you can get the Creators' Update now (pre-April 11) by downloading and running the Windows 10 Update Assistant. I've done this on my laptop so I can work on updating documentation around how to use Vagrant alongside the WSL/Ubuntu Bash (so you no longer have to download extra terminal emulators and switch between something like Cmder and Ubuntu Bash!).

geerlingguy commented Apr 7, 2017

Note that you can get the Creators' Update now (pre-April 11) by downloading and running the Windows 10 Update Assistant. I've done this on my laptop so I can work on updating documentation around how to use Vagrant alongside the WSL/Ubuntu Bash (so you no longer have to download extra terminal emulators and switch between something like Cmder and Ubuntu Bash!).

@whitecolor

This comment has been minimized.

Show comment
Hide comment
@whitecolor

whitecolor Jun 27, 2017

Is it possible some how to run .cmd files?

Seem to work: cmd.exe /c batch.cmd

whitecolor commented Jun 27, 2017

Is it possible some how to run .cmd files?

Seem to work: cmd.exe /c batch.cmd

@Artoria2e5

This comment has been minimized.

Show comment
Hide comment
@Artoria2e5

Artoria2e5 Jun 27, 2017

binfmt is more or less defined for binary executable formats, so defining text stuff like batch scripts there is likely a bad idea to start with. Once you get over that question, you can try the E (identify by extension) entry type.

Artoria2e5 commented Jun 27, 2017

binfmt is more or less defined for binary executable formats, so defining text stuff like batch scripts there is likely a bad idea to start with. Once you get over that question, you can try the E (identify by extension) entry type.

@therealkenc therealkenc removed the backlog label Jun 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment