Skip to content

Cannot define multiple commands in tasks.json #981

Closed

Description

@bbenoist

Hi,

I cannot find a way to define multiple tasks which executes different commands in the .vscode/tasks.json file of my project directory.

From what I understood, I can only declare a single TaskConfiguration within this file. Am I wrong?

To make my problem more understandable, let's say I would like to define 3 tasks with their own set of arguments:

  • foo: foo --arg
  • bar1: bar --arg 1
  • bar2: bar --arg 2

How can I make tasks.json reflect this need?

Activity

  1. added
    feature-request
    on Dec 4, 2015
  2. danielschmitz commented on Dec 6, 2015

    @danielschmitz

    Let me suggest a simple example to implementation (tasks.json) ....

    {
            // ROOT WITHOUT COMMAND
        "version": "0.1.0",
        "isShellCommand": true,
        "showOutput": "silent",
        "args": [],
    
        "tasks": [
            {
                 //CHILDREN WITH COMMAND ;)
                "taskName": "Build Type Script",
                "suppressTaskName": true,
                "isBuildCommand": true,
                "command": "tsc",
                "args": ["tsc -p ."]
            },
            {
                "taskName": "Open Browser",
                "suppressTaskName": true,
                "command": "live-server",
                "args": ["--open public_html"]
            }
        ]
    }
    

    AND CTRL+SHIFT+B:

    { "key": "ctrl+shift+b",          "command": "workbench.action.tasks.runTask" }
    
  3. usagi commented on Dec 6, 2015

    @usagi

    Hi, I need the feature too 👍 But, priority is low. Because, we can multiple command with the trick: http://qiita.com/usagi/items/5a0f4edc99420173abb3 ( Sorry, its wrote in Japanese. )

    The abstract of the trick are:

    • Use the top-level command to sh or cmd.exe or powershell.exe or any other common shell program.
    • Set the top-level args to -c ( with sh) or /c ( with cmd.exe ) or -Command ( with powershell.exe ).
    • Set sub-level args to any your command with \" quoted. ( eg. : "args" : "\"your-command arg1 arg2 arg3\"" )

    Example tasks.json:

    { "version": "0.1.0"
    , "command": "sh"
    , "isShellCommand": true
    , "showOutput": "always"
    , "args": [ "-c" ]
    , "tasks":
      [ { "taskName": "la"
        , "suppressTaskName": true
        , "args": [ "\"ls -la\"" ]
        }
      , { "taskName": "hoge"
        , "suppressTaskName": true
        , "args": [ "\"echo hoge\"" ]
        }
      , { "taskName": "build"
        , "suppressTaskName": true
        , "args": [ "\"mkdir -k build; cd build; cmake ..; make\"" ]
        }
      , { "taskName": "debug"
        , "suppressTaskName": true
        , "args": [ "\"cd build; gdb bin/my-executable\"" ]
        }
      ]
    }

    Its can run in the current release version ( 0.10.3 ). 🐰

  4. danielschmitz commented on Dec 6, 2015

    @danielschmitz

    Nice USAGI/USAGI.NETWORK (@usagi) , this is my solution:

    {
        "version": "0.1.0",
        "command": "cmd", 
        "isShellCommand": true,
        "showOutput": "silent",
        "args": ["/C"],
    
        "tasks": [
            {
            "taskName": "Build Type Script",
            "suppressTaskName": true,
            "isBuildCommand": true,
            "args": ["tsc -p ."]
            },
            {
            "taskName": "Open Browser",
            "suppressTaskName": true,
            "isBuildCommand": true,
            "args": ["live-server --open=public_html"]
            }
        ]
    }
    

    tip: cmd for windows, sh for linux

    shortcut: (override default build command)

    { "key": "ctrl+shift+b",          "command": "workbench.action.tasks.runTask" } 
    

    when i hit ctrl+shift+b, subtasks show up:

    05

    Bonus:

    you can define your own shortcut:

    { "key": "ctrl+shift+alt+o",          "command": "workbench.action.tasks.runTask/taskName" } 
    
  5. felixfbecker commented on Dec 8, 2015

    @felixfbecker
    Contributor

    This is very important. Say I want a test command and a build command. The test command needs to run mocha and the build command babel or tsc for example. "command" should be allowed for individual tasks in the tasks array.

    The workaround is nice, but it is not cross-platform and quotes have to be escaped.
    For cross-platform you would have to define

    {
      "linux": {
        "command": "sh",
        "args": ["-c"]
      },
      "osx": {
        "command": "sh",
        "args": ["-c"]
      },
      "windows": {
        "command": "powershell",
        "args": ["-Command"]
      }
    }

    and then duplicate the tasks property for every single OS :/

  6. usagi commented on Dec 8, 2015

    @usagi

    Felix Becker (@felixfbecker) It's nice follow-up 👍 We can use "windows", "linux", and "osx" for cross-platform portability.

  7. cfjedimaster commented on Dec 17, 2015

    @cfjedimaster

    Another plus one - and in my case, I can't use the workaround since I need a per OS switch and I can't rely on sh or cmd.

  8. felixfbecker commented on Dec 17, 2015

    @felixfbecker
    Contributor

    Raymond Camden (@cfjedimaster) Why can't you use the workaround exactly?

  9. cfjedimaster commented on Dec 17, 2015

    @cfjedimaster

    Because my top level command would be start on Windows and open on OSX. So I can't use just cmd or just start and pass different args.

  10. felixfbecker commented on Dec 17, 2015

    @felixfbecker
    Contributor

    Raymond Camden (@cfjedimaster) You mean like this?

    {
      "version": "0.1.0",
      "isShellCommand": true,
      "osx": {
        "command": "sh",
        "args": ["-c"],
        "tasks": [
          {"name": "run", "args": ["open mysuperawesomefile.txt"]}
        ]
      },
      "windows": {
        "command": "cmd",
        "args": ["/C"],
        "tasks": [
          {"name": "run", "args": ["start mysuperawesomefile.txt"]}
        ]
      }
    }
  11. cfjedimaster commented on Dec 17, 2015

    @cfjedimaster

    Yes. But to be clear, I wouldn't want to replicate all the tasks for both. Basically, I want to be able to do N tasks per file as the original requestor suggested. For me, 9 of the 10 tasks I want can all be in one definition. One of them is different though and needs to do X for Windows and Y for OSX.

  12. 81 remaining items

  13. guardrex commented on Mar 10, 2017

    @guardrex

    Vishal (@foo-baar) Old version of VSC? What's it say for the version under Help > About? Current version should be 1.10.2.

  14. dbaeumer commented on Mar 10, 2017

    @dbaeumer
    Member

    Commands per task work even in the old runner, but require 1.9

  15. foo-baar commented on Mar 10, 2017

    @foo-baar

    Dirk Bäumer (@dbaeumer) Your response raised good point to my suspicion: why my vscode was not auto updated or shown me a latest version is available ? Shall it be raised as a separate bug ? (case it's not known issue)

    (BTW: Updating to latest version fixed the task.json issue, thanks on that).

  16. dbaeumer commented on Mar 13, 2017

    @dbaeumer
    Member

    Vishal (@foo-baar) yes, please open a separate issue for that. VS Code should inform you about updates.

  17. foo-baar commented on Mar 13, 2017

    @foo-baar
  18. dbaeumer commented on Apr 26, 2017

    @dbaeumer
    Member

    Having different commands for different tasks is available since 1.9. I am closing the issue. If anyone sees problems with the support available since 1.9 please open a separate issue.

  19. radix commented on May 5, 2017

    @radix

    Dirk Bäumer (@dbaeumer) Hi! Since you closed this ticket (and also closed #7863 as a duplicate of this one), does that mean that vscode now supports concurrent execution of commands?

  20. dbaeumer commented on May 8, 2017

    @dbaeumer
    Member

    It does with the new terminal runner you need to opt in using "version": "2.0.0"

  21. DrYSG commented on May 8, 2017

    @DrYSG
  22. dbaeumer commented on May 9, 2017

    @dbaeumer
    Member

    Dr. YSG (@DrYSG) we will. We are currently working on making the terminal runner the default and writing corresponding documentation.

  23. DrYSG commented on May 9, 2017

    @DrYSG

    Dirk Bäumer (@dbaeumer) here is a idea (suggestion?) If I have 4 background tasks running, I don't really want to keep swapping the display for each task. I would like to be able to merge a few terminal outputs, and have a header (TASK 1: -> output string , etc. ) so that I can follow a few tasks at at a time and see what they are doing.

  24. vilicvane commented on Jun 12, 2017

    @vilicvane
  25. removed this from the Backlog milestone on Nov 10, 2017
  26. locked and limited conversation to collaborators on Nov 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requesttasks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions