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

Args not working in tasks.json using - "_runner":"terminal" #28036

Closed
gdxn96 opened this issue Jun 5, 2017 · 21 comments
Closed

Args not working in tasks.json using - "_runner":"terminal" #28036

gdxn96 opened this issue Jun 5, 2017 · 21 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug *duplicate Issue identified as a duplicate of another issue(s) tasks Task system issues
Milestone

Comments

@gdxn96
Copy link

gdxn96 commented Jun 5, 2017

  • VSCode Version: 1.12.2
  • OS Version: Windows 10
  • Terminal: Bash for Windows
{
    "version": "0.1.0",
    "options": {
        "cwd": "${workspaceRoot}"
    },
    "_runner": "terminal",
    "tasks": [
        {
            "taskName": "Install Pip Dependancies",
            "command": ".env/bin/python",
            "isShellCommand": true,
            "args": ["-m", "pip", "install", "-r", "requirements/dev.txt"],
            "showOutput": "always"
        }
    ]
}

Running this task does not act as expected, it opens the terminal as it should, then it opens a python interpreter, ignoring all my nice args. Have I done something wrong or is it a bug? I've deleted all my other tasks for legibility.

@kieferrm
Copy link
Member

kieferrm commented Jun 5, 2017

I tried that on macOS with 1.12.2 and insiders. Works in both cases without issues.

@kieferrm kieferrm added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Jun 5, 2017
@dbaeumer
Copy link
Member

dbaeumer commented Jun 6, 2017

@gdxn96 which Bash system to you use. The Windows Subsystem for Linux ?

@dbaeumer dbaeumer added info-needed Issue requires more information from poster tasks Task system issues and removed *question Issue represents a question, should be posted to StackOverflow (VS Code) labels Jun 6, 2017
@dbaeumer
Copy link
Member

dbaeumer commented Jun 6, 2017

I can reproduce using Ubuntu bash.exe. The shell args constructed look like this:

capture

@Tyriar you once told me that under Windows I must pass one string as a shell arg in case of additional arguments. Is there anything else I need to consider. Must the command passed to echo in this case be quoted ?

@dbaeumer
Copy link
Member

dbaeumer commented Jun 6, 2017

Please note that to easier reproduce I modified the command from .env/bin/python to echo.

@dbaeumer
Copy link
Member

dbaeumer commented Jun 6, 2017

The code works as expected using cmd.exe or powershell.

@gdxn96
Copy link
Author

gdxn96 commented Jun 6, 2017

Sorry yes, Windows Subsystem for Linux is whats causing the issue

@Tyriar
Copy link
Member

Tyriar commented Jun 6, 2017

@dbaeumer so the issue here seems to be related to us not giving bash.exe what it's expecting. Needs some experimentation.

@dbaeumer dbaeumer added bug Issue identified by VS Code Team member as probable bug and removed info-needed Issue requires more information from poster labels Jun 6, 2017
@dbaeumer dbaeumer added this to the June 2017 milestone Jun 6, 2017
@dbaeumer
Copy link
Member

@Tyriar assigning you as well. If you give me some hints I could look into this as well.

@Tyriar
Copy link
Member

Tyriar commented Jun 12, 2017

@dbaeumer I would expect either as args or the single string should work. Not sure what's sent now but maybe for bash.exe on Windows you need a conditional that uses the string[] approach?

@giovdk21
Copy link

Hi,
I've the same issue; this is with the insiders build (2017-06-09) on Windows using bash.

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Test 1",
            "type": "shell",
            "command": "uname",
            "isShellCommand": true,
            "echoCommand": true,
            "args": ["-a"],
            "showOutput": "always"    
        }
    ]
}

Expected result: Linux HostName 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux
Actual result: Linux

@Tyriar Tyriar removed their assignment Jun 22, 2017
@dbaeumer
Copy link
Member

@Tyriar I tried both using as single string or a string[]. Both result in the same behavior under Windows of not running the task correctly. What I noticed is that the winpty-agent closed but the electron process started with --type=terminal still hangs around afterwards when passing the args separately:

capture

When passing the args as one string the execution fails with:

The terminal process terminated with exit code: 3221225477

Can you please investigate. I ran out of ideas / options.

@dbaeumer dbaeumer assigned Tyriar and unassigned dbaeumer Jun 26, 2017
@Tyriar Tyriar modified the milestones: July 2017, June 2017 Jun 26, 2017
@giovdk21
Copy link

giovdk21 commented Jul 8, 2017

For a temporary workaround to this one, please see also: #22663 (comment)

@dbaeumer
Copy link
Member

@Tyriar please see #30417 (comment). It contains a work around by quoting the command line. Is this what I am supposed to do for bash under Windows?

@0not
Copy link

0not commented Jul 12, 2017

@dbaeumer According to the bash man page, the argument to bash -c should be quoted. Anything after the string to be executed is passed in as parameters.

-c string
If the -c option is present, then commands are read from string. If there are arguments 
after the string, they are assigned to the positional parameters, starting with $0.

For example, "command": "\"echo $0\" Hello" prints "Hello" as expected.

It appears that the command does need to be quoted when passed to bash -c, but I don't know enough about the task system to say if that's feasible. I just figured I'd pass this information on.

@giovdk21
Copy link

giovdk21 commented Jul 12, 2017

@dbaeumer & @0not could you please have a look at my previous comment or here?

The workaround I implemented works in a similar way but basically I'm collecting all the shell arguments with a powershell script and then calling C:\Windows\System32\bash.exe -c "$args_str"

This not only fixes it but it also allows for other parameters to be appended at the end. For example one extension (solargraph) is defining a command that it needs to run and then appending different arguments depending on the action it wants to perform.

Another thing to consider is that the path passed from the task / extension is in the windows format, so my workaround also tries to convert that into a linux path.

@dbaeumer
Copy link
Member

It is correct that the arg passed to -c should be quoted but somehow this is done by the terminal correctly when running bash under Linux and Mac OS but obviously not under Windows. We need to understand what is different in the xterm code and whether quoting it for Windows is the right thing to do.

@0not
Copy link

0not commented Jul 14, 2017

I believe I've found a solution, but I don't know how correct it is. In src/vs/workbench/parts/tasks/electron-browser/terminalTaskSystem.ts change line 475 from shellLaunchConfig.args = Platform.isWindows ? shellArgs.join(' ') : shellArgs; to shellLaunchConfig.args = Platform.isWindows && basename !== 'bash.exe' ? shellArgs.join(' ') : shellArgs;. Several lines before this Windows is treated specially with three options (powershell, bash, or cmd), but on this line the only differentiation is made between Windows and other (presumably bash on Linux/Mac). The logic for isWindows should really be not bash.

I would create a pull request for this, but embarrassingly, I don't know how and I don't have time tonight. I've tested this solution by building vscode on Windows 10, but I don't know of any unforeseen side effects.

@Tyriar
Copy link
Member

Tyriar commented Jul 14, 2017

@dbaeumer On Windows you use the different escaping method (string), I'm assuming since bash.exe redirects to actual bash on Ubuntu it requires the same format (string[]).

You could try see if it's bash.exe inside %windir%\(sysnative|system32|syswow64) then use the string[] method?

@Tyriar Tyriar modified the milestones: August 2017, July 2017 Jul 21, 2017
@dbaeumer
Copy link
Member

dbaeumer commented Aug 2, 2017

@Tyriar #30417 shows the same problem for bash from git install (so no Linux Subsystem). So should I use string[] for git bash as well. Would be good to understand what the terminal does so I can implement the right fix on my side.

@Tyriar
Copy link
Member

Tyriar commented Aug 2, 2017

@dbaeumer all the examples in the issue that introduced the string format appear to be cmd.exe (#19078, microsoft/node-pty#41), maybe it needs to only apply to cmd.exe? I don't have much knowledge into this area other than cmd.exe doesn't want the args in the "proper" argv format. It needs some experimentation to figure out what's going on.

The formatting is done on the string | string[] here, after that it's handed off to winpty which is largely a black box to me. That function was added in microsoft/node-pty@ed3c9da, before that arguments didn't work at all on Windows (fixed chjj/pty.js#137).

@dbaeumer
Copy link
Member

Fixed by fixing #30417

@dbaeumer dbaeumer added the *duplicate Issue identified as a duplicate of another issue(s) label Aug 25, 2017
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 17, 2017
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 *duplicate Issue identified as a duplicate of another issue(s) tasks Task system issues
Projects
None yet
Development

No branches or pull requests

6 participants