2

I am trying to run the Windows 10 Linux Subsystem from Visual Studio 2015's Post-Build Command Line. That is, I have a command, whose output will be piped to bash, for example xyz | bash. bash should in turn start the Windows 10 Linux Subsystem and execute the command.

This works perfectly when running the command from the regular CMD.exe Command Line or .bat files. However, when running this from the Visual Studio 2015 Post-, Pre-Build- or Pre-Link-Event Command Line directly, via a call cmd /C call or an external .bat file as proxy, this fails with error code 255 and prints something like "Command 'bash' not found.". When trying to use the complete path to the bash.exe this fails, too.

How can I run bash from Visual Studio's Command Line?

Sidenote: I am trying to run this on a C/C++ Project.

HerpDerpington
  • 3,751
  • 4
  • 27
  • 43
  • Are you aware of the fact that you can _accept_ answers on Stack Overflow? – m93a Nov 02 '17 at 07:21
  • 1
    @m93a Oh, sorry, I forgot about this question since solving this just caused a different problem... – HerpDerpington Nov 04 '17 at 13:08
  • What problem? If it's bash-related, maybe I could help. – m93a Nov 05 '17 at 17:14
  • @m93a Not directly... https://stackoverflow.com/questions/47126688/unicodeencodeerror-with-visual-studio-post-build-command-line – HerpDerpington Nov 05 '17 at 23:00
  • I believe this post answers your question I don't quite understand your question but I use bash through visual code all the time and this is what I followed to do it. [Bash on Windows from Visual Studio Code](https://stackoverflow.com/questions/42606837/how-to-use-bash-on-windows-from-visual-studio-code-integrated-terminal) – xlok3x Oct 29 '17 at 02:42

1 Answers1

4

I faced this problem too when using bash from my 32-bit C++ application.

The thing is that bash is 64-bit only – when you try to use it from a 32-bit app, your call to C:\Windows\System32\bash.exe gets redirected to C:\Windows\SysWOW64\bash.exe which does not exist.

To bypass the redirect you have to use C:\Windows\Sysnative\bash.exe when calling bash from a 32-bit app. I actually made a batch (.bat) proxy that I added to the PATH to make things easier.

bash.bat:

@echo off

if exist "C:\Windows\Sysnative\bash.exe" (
  C:\Windows\Sysnative\bash.exe %*
) else (
  C:\Windows\System32\bash.exe %*
)
m93a
  • 8,866
  • 9
  • 40
  • 58