I've been setting up Ubuntu user mode with node and npm and wanted to run a task from Visual Studio code to call gulp to transpile Typescript to Javascript in that environment.
If from the command line (cmd.exe) I execute bash -c "gulp" then it works exactly as I would expect it to... Running the default task as defined in my gulpfile.js.
But if I try and set up a task in tasks.json, it tells me it's running the exact same command, but there's no output and no javascript generated.
Steps to Reproduce:
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"showOutput": "always",
"echoCommand": true,
"args": [
"-c"
],
"tasks": [{
"taskName": "Gulp Typescript Job",
"suppressTaskName": true,
"args": [
"\"gulp\""
],
"isBuildCommand": true,
"problemMatcher": "$gulp-tsc",
"showOutput": "always",
"echoCommand": true
}]
}
Edit: formatting (still not great, sorry)
Lets investigate for May. But no promise :-)
Sure, I can imagine this is fairly low priority as far as bugs are concerned - but it sure would be a nice feature to use Keyboard shortcuts to perform various tasks in Bash on Ubuntu on Windows :-)
This simple example doesn't work either:
{
"version": "0.1.0",
"command": "bash.exe",
"isShellCommand": true,
"showOutput": "always",
"echoCommand": true,
"args": [
"-c", "echo Hello World"
]
}
it produces:
'bash.exe' is not recognized as an internal or external command,
operable program or batch file.
Looks like bash is not known in an spawned cmd.exe.
Interestingly executing this in a command prompt
cmd.exe /s /c bash -c "echo Hello World"
works
Trying this
{
"version": "0.1.0",
"command": "C:\\Windows\\System32\\bash.exe",
"showOutput": "always",
"echoCommand": true,
"args": [
"-c", "echo Hello World"
]
}
doesn't work either. It prints:
Failed to launch external program C:\Windows\System32\bash.exe -c echo Hello World.
spawn C:\Windows\System32\bash.exe ENOENT
This is either a node problem or a general bash problem. Trying
var cp = require('child_process');
cp.exec('bash -c "echo Hello World"', function(error, out, err) {
if (error) {
console.log(error);
} else {
console.log(out);
console.log(err);
}
});
doesn't work either in a native node environment.
No further action planned for May. Need to see if spawning bash from a different programming language (e.g. C#) works
I got this working without any issues when answering his So question. http://stackoverflow.com/a/37378311/1156119
Windows 10 64 bit, just installed. I have a feeling now that it would have been git bash that it was actually running in.
The Git Bash bit makes sense - but kinda defeats what I'm trying to do here; segregate dev tooling to Ubuntu on Windows.
I had trouble getting the integrated terminal running cmd.exe to recognize bash. I think it's integrated in some weird way. My impression with playing around with it for the first time a few days ago was that it's definitely early days and probably not worth trying to integrate until it's matured more.
I had an issue similar to this when trying to launch debug with bash. What I found what that VSCode is 32 bit and bash.exe is only available in the 64 bit system32 folder. 32 bit apps get redirected to the SysWOW64 folder.
As a work around you can copy bash.exe from System32 to the SysWOW64 folder and VSC will be able to find it.
I tried your suggested workaround before and could not manage to get it to call bash for this purpose.
As a work around you can copy bash.exe from System32 to the SysWOW64
@Aigeec: Unfortunately it doesn't work. Output is empty when I try to run any bash command using task.
My tasks:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"showOutput": "always",
"tasks": [
{
"taskName": "Run python in bash",
"suppressTaskName": true,
"args": ["python", "${file}"]
},
{
"taskName": "Test",
"args": [
"python"
]
}
]
}
@dbaeumer @JasonDunbar any luck with solving this problem?
Unfortunately still no solution... I gave up and go to Bash direct, instead of trying to call from within VSCode.
For what it's worth, having same problem from within Python. I can run bash commands manually from the command line but that's all.
subprocess.run(["bash.exe", "-c", "pwd"])
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\ktw\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 693, in run
with Popen(_popenargs, *_kwargs) as process:
File "C:\Users\ktw\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in init
restore_signals, start_new_session)
File "C:\Users\ktw\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
subprocess.run(["cmd.exe", "/c", "bash.exe ls"])
'bash.exe' is not recognized as an internal or external command,
operable program or batch file.
CompletedProcess(args=['cmd.exe', '/c', 'bash.exe ls'], returncode=1)
subprocess.run(["cmd.exe", "/c", "bash.exe", "-c", "ls"])
'bash.exe' is not recognized as an internal or external command,
operable program or batch file.
CompletedProcess(args=['cmd.exe', '/c', 'bash.exe', '-c', 'ls'], returncode=1)
...and still no further on what the plan is here or whether or not it will ever get a planned release milestone. @dbaeumer any news?
I retried it and trying to spawn bash.exe from the Linux subsystem still fails on node. So there is little VS Code can do to fix this. Would be interesting to know whether bash.exe from the Linux subsystem can be spawn in C# or Python to understand where this is a node or a bash.exe problem.
Any news on this issue please? Do we require a 'WSL task runner'?
@Tyriar pointed out to me that we should try using C:\Windows\Sysnative\bash.exe.
You can run a task in the windows bash via bat/sh proxies. So for the python example above you could set up your task as:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "task.bat",
"isShellCommand": true,
"showOutput": "always",
"tasks": [
{
"taskName": "Run python in bash",
"suppressTaskName": true,
"args": [
"python",
"${relativeFile}"
]
}
]
}
Note: This uses ${relativeFile} not file. File passes a windows path and doesn't work.
The task.bat file would be a one-liner:
C:/Windows/sysnative/bash.exe ./task.sh %*
Referring to a two-liner:
#!/bin/bash
exec "$@"
Output is for a file public/hello.py containing print "Hello World!":
C:/Windows/sysnative/bash.exe ./task.sh python public/hello.py
Hello World!
I am also getting this when calling an external batch file that is then calling bash, e.g.:
@echo off
set "SystemPath=%SystemRoot%\\System32"
IF EXIST %WINDIR%\\sysnative\\reg.exe (
set "SystemPath=%SystemRoot%\Sysnative"
echo. "32-bit process..."
)
set env="/usr/local/libdragon"
IF %1.==. (
echo. "no parameter"
%SystemPath%\\bash --verbose -c "export N64_INST=%env%; make"
) ELSE (
echo. "parameter: %1"
%SystemPath%\\bash --verbose -c "export N64_INST=%env%; make %1"
)
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "build",
"isShellCommand": true,
"args": [],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "Release",
"args": []
},
{
"taskName": "Debug",
"args": ["debug"]
},
{
"taskName": "Clean",
"args": ["clean"]
}
]
}
However if I call the batch script from the integrated terminal it runs correctly!
from a quick search on google, error 0x80070057 is caused by using legacy console... Is VS code using a legacy console for tasks?!
hey @networkfusion, this works for me on W10 14986.1000 64-bit聽with VSC 1.7.2.
I wonder聽do you have legacy mode set on command prompt?
@Aigeec No, legacy mode is not on, I don't have any problems from anywhere else but vscode tasks... my os version is 14393.479 so if that is the issue I guess I will be waiting a while...
I think I read that the issue is fixed in the Windows 10 Insiders build; I guess that W10 14986.1000 is an Insiders build.
Yes, 14986.1000 is a fast ring insider build.
using聽/Sysnative/bash.exe directly works for me in聽14986
@tinaun - that worked for me. Fixed both running bash in the "terminal" mode and the tasks format. Thanks!
I have the same issue, when I do Ctrl + Shift + b the command appears in the ouput but nothing happens:
{
"version": "0.1.0",
"command": "bash",
"isShellCommand": true,
"args": ["-l","-c"],
"showOutput": "always",
"echoCommand": true,
"tasks": [{
"taskName": "Compile",
"suppressTaskName": true,
"args": [
"\"make\""
],
"isBuildCommand": true,
"isBackground": false,
"showOutput": "always"
}]
}
If I change the command to "C:\\Windows\\Sysnative\\bash.exe" then I get the following:
EDIT: I have Windows 10 version 14393.0, and Visual Studio Code version 1.9.1.
Same issue as above.
Running VsCode v 1.10.2, Windows 10 Pro v 14.393.693
Any idea when that insider build will go public or if we can sideload it?
@kushagharahi since this issues discusses various different aspects, what issue do you have. The terminal runner which supports executing bash.exe and has correct encoding support is available in 1.10 but needs to be opted in using version: "2.0.0" property in the tasks.json
@dbaeumer turning the version to "2.0.0" indeed makes a difference. Now I run into a different issue. My task.json is
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"command": "C:\\Windows\\sysnative\\bash.exe",
"isShellCommand": false,
"args": ["-c \"echo Hello World\""],
"showOutput": "always",
"echoCommand": true
}
and I get the following message:
/bin/bash: - : invalid option
Usage: /bin/bash [GNU long option] [option] ...
/bin/bash [GNU long option] [option] script-file ...
GNU long options:
--debug
--debugger
--dump-po-strings
--dump-strings
--help
--init-file
--login
--noediting
--noprofile
--norc
--posix
--rcfile
--restricted
--verbose
--version
Shell options:
-ilrsD or -c command or -O shopt_option (invocation only)
-abefhkmnptuvxBCHP or -o option
Press any key to close the terminal
Any idea why it doesn't seem to catch -c properly?
Also weird is the fact that it doesn't echo my command ...
Echo support in the terminal is still under development :-)
There is still a bug in the terminal with arg escaping and spaces. This will be fixed for the next release as well. This I think is the reason for not getting the -c correctly.
@dbaeumer I'm not sure if there is an issue about it. Would it be possible to specify a build terminal for a task? Manually appending -c and specifying the bash executable looks rather hacky (and not portable).
you can simply use isShellCommand: true which will pick the default shell. If you want to control the shell you need to specify it. If you want to make this OS specific you can use the OS specific properties windows, linux, ...
If you want to control the shell you need to specify it
Is there another way to select the shell than prepending shellname -c?
Yes you can do the following on latest
isShellCommand: {
"executable": "C:\\Windows\\sysnative\\bash.exe",
"args": ["-c"]
}
However escaping was still broken. I fixed a bug there yesterday,
Win Build: 15063.250
I am able to execute the task on WSL here is my task json
{
"version": "0.1.0",
"command": "C:\\WINDOWS\\Sysnative\\bash.exe",
"isShellCommand": true,
"args": ["-c", "\"make"],
"showOutput": "always",
"echoCommand": true,
"tasks": [
{
"taskName": "flash\"",
"isBuildCommand": true
}
]
}
add the following line to settings.json to set Bash on Windows as default terminal of your project.
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"
and then set tasks.json as the following, make sure you put extra quotes to the beginning of command and the end of arguments, and set suppressTaskName to true in your sub-tasks.
{
"version": "2.0.0",
"command": "\"make",
"type": "shell",
"tasks": [
{
"taskName": "build",
"args": [
"clean",
"all\""
],
"suppressTaskName": true
}
]
}
The whole thing is equivalent to
"bash.exe" -c "make clean all"
@tl1u16 with the new task 2.0.0 this should be written as follows:
{
"version": "2.0.0",
"tasks": [
{
"taskName": "build",
"command": "make clean all",
"type": "shell",
}
]
}
@dbaeumer I'm using vscode latest version (1.15) and using task 2.0.0. Yet, I can only make args work the way suggested by @tl1u16 (yes, using the now deprecated suppressTaskName and the extra quotes). I've tried both:
{
"version": "2.0.0",
"tasks": [
{
"taskName": "build",
"type": "shell",
"command": "clang++-4.0 main.cpp"
}
]
}
and
{
"version": "2.0.0",
"tasks": [
{
"taskName": "build",
"type": "shell",
"command": "clang++-4.0",
"args": ["main.cpp"]
}
]
}
both runs as if no argument was provided. I also tested with echo (echo test) and aptitude (aptitude search), all ran as if no argument was provided.
@andre-ss6 this is discussed in https://github.com/Microsoft/vscode/issues/28036 and a problem with bash or the Linux subsystem. We are looking into how to best fix this.
I had similar problem with executing commands in my default git/bash shell (_VSC_ 1.15.1; _Windows 10 Pro_ - x64) and @tl1u16 hint with "\"command" worked like a charm.
_User Settings:_
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"
_or by shortcut_
ctrl+shift + pand type: _Terminal: Select Default Shell_
_.vscode/tasks.json:_
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "Run PHPunit",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"command": "\"phpunit test --testdox"
}
]
}
_.vscode/tasks.json:_
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "Run PHPunit",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"command": "\"phpunit test --testdox",
"options": {
"shell": {
"executable": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": [
"-c"
]
}
}
}
]
}
The problem with args in a command when executing in bash (both git and WSL) got addressed for 1.16. So the "\"command" trick should no longer be needed.
I confirm that in VSC 1.6 the problem no longer exist and use of "\"command" hack causes syntax error: _unexpected end of file_. Thank you VSC team and all contributors for the effort 馃憤.
I tried this today with 1.23.0.
{
"version": "2.0.0",
"tasks": [
{
"label": "pwd",
"type": "shell",
"options": {
"shell": {
"executable": "C:\\Windows\\sysnative\\bash.exe",
"args": [
"-c"
]
}
},
"command": "pwd"
}
]
}
This does not work, it just hangs without any output.
But there are many way to make it work now.
option and replace command with bash -c pwdoption and set it in user settings "terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\bash.exe"But I still wonder why the way I tried first does not work.
I was able to reproduce this. Interestingly using "executable":"bash.exe" works as expected.
@Tyriar can you comment on why "executable": "C:\\Windows\\sysnative\\bash.exe" doesn't work. The shell launch config I generate looks like this:

Set any arbitrary string that does not exist as executable will cause the console hanging. e.g. "executable": "qazxsw"
I think vs code just can't find the executable? BTW, I think vs code should give an error message in case of the executable can't be found, instead of just hanging.
Oh, I found "executable": "C:\\Windows\\System32\\bash.exe" works. And "terminal.integrated.shell.windows": "C:\\Windows\\System32\\bash.exe" in settings.json also works.
However, why sysnative works in settings.json but not in tasks.json?
can you comment on why "executable": "C:\Windows\sysnative\bash.exe" doesn't work.
sysnative should only ever be used on 32-bit VS Code on a 64-bit system, I wrote about this here: http://www.growingwiththeweb.com/2017/08/windows-wow64.html
However, why sysnative works in settings.json but not in tasks.json?
Because the terminal has logic to translate sysnative to system32 when running a 64-bit executable, this was to help with migration when 64-bit code was introduced.
@Tyriar thanks. Can I somehow reuse that code when creating a terminal ?
It's here:
You're already calling it from here:
I do call mergeDefaultShellPathAndArgs but only if the task doesn't specify a special shell. So I will reuse your code snippet.
Integrated the code into the terminal task runner. @Tyriar thanks.
Based on the discussion it seems like this might already be fixed by multiple changes. Anyone still having this issue?
This issue has been closed automatically because it needs more information and has not had recent activity. See also our issue reporting guidelines.
Happy Coding!
Most helpful comment
I have the same issue, when I do
Ctrl + Shift + bthe command appears in the ouput but nothing happens:If I change the command to

"C:\\Windows\\Sysnative\\bash.exe"then I get the following:EDIT: I have Windows 10 version 14393.0, and Visual Studio Code version 1.9.1.