vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Task not executing bash, yet echoed command works fine in cmd

Open JasonDunbar opened this issue 10 years ago • 53 comments

  • 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:

  1. 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)

JasonDunbar avatar May 20 '16 14:05 JasonDunbar

Lets investigate for May. But no promise :-)

dbaeumer avatar May 23 '16 10:05 dbaeumer

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 :-)

JasonDunbar avatar May 23 '16 11:05 JasonDunbar

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

dbaeumer avatar May 25 '16 12:05 dbaeumer

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

dbaeumer avatar May 25 '16 12:05 dbaeumer

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

dbaeumer avatar May 25 '16 12:05 dbaeumer

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.

Tyriar avatar May 25 '16 16:05 Tyriar

The Git Bash bit makes sense - but kinda defeats what I'm trying to do here; segregate dev tooling to Ubuntu on Windows.

JasonDunbar avatar May 25 '16 18:05 JasonDunbar

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.

Tyriar avatar May 25 '16 19:05 Tyriar

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.

Aigeec avatar Jul 18 '16 11:07 Aigeec

I tried your suggested workaround before and could not manage to get it to call bash for this purpose.

JasonDunbar avatar Jul 18 '16 16:07 JasonDunbar

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?

piotrek-k avatar Sep 29 '16 17:09 piotrek-k

Unfortunately still no solution... I gave up and go to Bash direct, instead of trying to call from within VSCode.

JasonDunbar avatar Sep 29 '16 18:09 JasonDunbar

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)

m0rb1us avatar Oct 29 '16 12:10 m0rb1us

...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?

JasonDunbar avatar Oct 31 '16 06:10 JasonDunbar

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.

dbaeumer avatar Oct 31 '16 10:10 dbaeumer

Any news on this issue please? Do we require a 'WSL task runner'?

daldr-ntml avatar Nov 22 '16 08:11 daldr-ntml

@Tyriar pointed out to me that we should try using C:\Windows\Sysnative\bash.exe.

dbaeumer avatar Nov 22 '16 17:11 dbaeumer

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!

Aigeec avatar Nov 23 '16 21:11 Aigeec

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?!

networkfusion avatar Dec 13 '16 15:12 networkfusion

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

Aigeec avatar Dec 13 '16 21:12 Aigeec