Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JasonDunbar opened this issue May 20, 2016 · 53 comments
Closed

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

JasonDunbar opened this issue May 20, 2016 · 53 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster tasks Task system issues WSL Issue when using WSL
Milestone

Comments

@JasonDunbar
Copy link

JasonDunbar commented May 20, 2016

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

@dbaeumer dbaeumer added bug Issue identified by VS Code Team member as probable bug tasks Task system issues labels May 23, 2016
@dbaeumer dbaeumer added this to the May 2016 milestone May 23, 2016
@dbaeumer
Copy link
Member

Lets investigate for May. But no promise :-)

@JasonDunbar
Copy link
Author

JasonDunbar commented May 23, 2016

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

@dbaeumer
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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 dbaeumer modified the milestones: June 2016, May 2016 May 25, 2016
@Tyriar
Copy link
Member

Tyriar commented May 25, 2016

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.

@JasonDunbar
Copy link
Author

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

@Tyriar
Copy link
Member

Tyriar commented May 25, 2016

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.

@dbaeumer dbaeumer modified the milestones: Backlog, June 2016 Jun 29, 2016
@Aigeec
Copy link

Aigeec commented Jul 18, 2016

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.

@JasonDunbar
Copy link
Author

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

@piotrek-k
Copy link

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?

@JasonDunbar
Copy link
Author

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

@m0rb1us
Copy link

m0rb1us commented Oct 29, 2016

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)

@JasonDunbar
Copy link
Author

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

@dbaeumer
Copy link
Member

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.

@daldr-ntml
Copy link

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

@dbaeumer
Copy link
Member

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

@Aigeec
Copy link

Aigeec commented Nov 23, 2016

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!

@networkfusion
Copy link

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

@dbaeumer
Copy link
Member

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

@devnoname120
Copy link

If you want to control the shell you need to specify it

Is there another way to select the shell than prepending shellname -c ?

@dbaeumer
Copy link
Member

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,

@123swk123
Copy link

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
        }
    ]
}

@tl1u16
Copy link

tl1u16 commented Jul 26, 2017

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"

@dbaeumer
Copy link
Member

dbaeumer commented Aug 2, 2017

@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",
        }
    ]
}

@andre-ss6
Copy link

andre-ss6 commented Aug 14, 2017

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

@dbaeumer
Copy link
Member

@andre-ss6 this is discussed in #28036 and a problem with bash or the Linux subsystem. We are looking into how to best fix this.

@weinand weinand added the WSL Issue when using WSL label Aug 16, 2017
@idbartosz
Copy link

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.

1. With changed terminal integrated shell

User Settings:
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe"

or by shortcut ctrl+shift + p and 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"
        }
    ]
}

2. Without messing in default terminal integrated 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",
            "options": {
                "shell": {
                    "executable": "C:\\Program Files\\Git\\bin\\bash.exe",
                    "args": [
                        "-c"
                    ]
                }
            }
        }
    ]
}

@dbaeumer
Copy link
Member

dbaeumer commented Sep 7, 2017

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.

@idbartosz
Copy link

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

@huww98
Copy link

huww98 commented May 4, 2018

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.

  • replace shell executable with git bash
  • remove the option and replace command with bash -c pwd
  • remove the option 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.

@dbaeumer
Copy link
Member

dbaeumer commented May 7, 2018

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:

capture

@huww98
Copy link

huww98 commented May 7, 2018

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.

@huww98
Copy link

huww98 commented May 7, 2018

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?

@Tyriar
Copy link
Member

Tyriar commented May 11, 2018

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.

@dbaeumer
Copy link
Member

@Tyriar thanks. Can I somehow reuse that code when creating a terminal ?

@dbaeumer
Copy link
Member

I do call mergeDefaultShellPathAndArgs but only if the task doesn't specify a special shell. So I will reuse your code snippet.

@dbaeumer
Copy link
Member

Integrated the code into the terminal task runner. @Tyriar thanks.

@alexr00
Copy link
Member

alexr00 commented Nov 8, 2018

Based on the discussion it seems like this might already be fixed by multiple changes. Anyone still having this issue?

@alexr00 alexr00 added the info-needed Issue requires more information from poster label Nov 8, 2018
@vscodebot vscodebot bot closed this as completed Nov 15, 2018
@vscodebot
Copy link

vscodebot bot commented Nov 15, 2018

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!

@vscodebot vscodebot bot locked and limited conversation to collaborators Dec 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster tasks Task system issues WSL Issue when using WSL
Projects
None yet
Development

No branches or pull requests