How to launch Bash on Ubuntu on Windows from third-party application?

3

I've installed Windows Subsystem for Linux (WSL) in order to Bash on Ubuntu on Windows (in the following abbreviated to “Bash”.) In cmd.exe I can run bash -c gcc --version as well as I can use cmd -k bash -c gcc --version from the start menu. However, I noticed that I cannot run the same command from third-party applications, e.g. Sublime Text or Atom.

Consider the following build system for Sublime Text and, for the moment, ignore that fact that this wouldn't build anything:

{
  "cmd": [ "bash", "-c" "gcc", "--version" ],
  "working_dir": "${project_path:${folder}}",
  "selector" : "source.c"
}

Running the build command will result into Error: 0x80070057. With legacy mode for cmd.exe enabled, the error reads Unsupported console settings. In order to use this feature the legacy mode must be disabled.

Among the other things I already tried to get it to work:

  1. Using absolute paths to bash.exe, e.g. %SystemRoot%\System32\bash.exe

  2. Run a Batch file in the build tool (content: bash -c gcc --version). Notably, the Batch file works when run from cmd.exe

  3. Change the build command to [ "cmd", "/k", "bash", "-c" "gcc", "--version"]

  4. Add "shell": true to my build file

At times the error changes to ”[bash] is not recognized as an internal or external command”, even though C:\Windows\System32 is in my path.

Is there a limitation that Bash can only be launched from cmd.exe? Are there any workarounds that would allow my to launch batch from Sublime Text?

idleberg

Posted 2016-10-28T16:17:42.420

Reputation: 1 200

Did you disable the legacy mode for cmd? You can see how to disable legacy mode in the comments of the top answer.

– DrZoo – 2016-10-28T16:54:34.840

Couple ideas... Try changing the cmd line to "cmd": [ "cmd.exe", "-k", "bash -c gcc --version" ], and/or try adding shell: true. – Ƭᴇcʜιᴇ007 – 2016-10-28T17:17:18.100

Thanks for your suggestions, I already tried these (as mentioned in the question). I edited my post and put my other attempts into a numbered list, which should be more legible. – idleberg – 2016-10-28T18:43:36.757

Answers

3

I think you can give a try to this solution.

Using Windows Subsystem for Linux (WSL) from Sublime Text

And no, it isn't necessary to replace bash with bash.exe.

Fontinalis

Posted 2016-10-28T16:17:42.420

Reputation: 31

0

I don't have your environment to test this, but I suggest replacing "bash" with "bash.exe". The Windows cmd.exe command requires the .exe suffix to execute the bash.exe command. The WSL command /usr/bin/bash is not the same command as the Windows command C:\Windows\System32\bash.exe.

rhmccullough

Posted 2016-10-28T16:17:42.420

Reputation: 381