Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode task wraps command in ' ' quotes breaking args on multi-line commands

Im trying to create a VSCode task that runs a command with some arguments.

"tasks": [
    {
        "label": "Execute in Max",
        "type": "shell",
        "command": "cd\\; C:\\MXSPyCOM.exe",
        "args": [
            "-f",
            "'${file}'"
        ],
        "problemMatcher": []
    }
]

and from that I get the error:

& : The module 'cd' could not be loaded. For more information, run 'Import-Module cd'. At line:1 char:3 + & 'cd\; C:\MXSPyCOM.exe' -f 'c:\Users\ ... + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (cd\; C:\MXSPyCOM.exe:String) [], CommandNotFoundException + FullyQualifiedErrorId : CouldNotAutoLoadModule

Im fairly certain the problem is the command its trying to execute: 'cd\; C:\MXSPyCOM.exe' -f 'c:\Users\ The main command block is wrapped up in single quotes for some reason, which makes shell think its a single command, when its multiple.

This didnt use to happen, and I had this exact command working just fine a few months ago when i last used it. Any idea what could be wrong?

like image 686
Olli Avatar asked Jan 29 '23 08:01

Olli


1 Answers

Yes, up until 1.21.0 vscode just gave warning when having spaces in args, the latest version wrapping commands and args with single quote when they have spaces inside. Just break the command to have no spaces in it, either by

"command": "cd\\;C:\\MXSPyCOM.exe",

or

"command": "cd\\;",
"args": [
            "C:\\MXSPyCOM.exe",
            ...

When have no such option (such as passing commands to ssh session) what I do is:

"command": "ssh",
"args": [
            "host_name",
            "bash",
            "-c",
            "'\"",
            "cd /some_dir;",
            ...
            "\"'"
        ],

The quick and dirty workaround is to not use the args field at all, and have the full command in command.

Another solution is to write your own scripts, and just call them from the tasks.json

like image 103
idanp Avatar answered Apr 12 '23 23:04

idanp