Task not executing bash, yet echoed command works fine in cmd
- VSCode Version: 1.1.1
- OS Version: Windows 10 Pro Insider Preview Build 14342
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:
-
Set up a task to run bash like so:
{ "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?
https://github.com/Microsoft/BashOnWindows/issues/7