VagrantAI
VagrantAI

Reputation: 670

Launch vscode task in external terminal via tasks 2.0.0

Is it possible to launch bat file via external terminal, not inside a vscode terminal?

Task sample:

{
    "label": "Build",
    "type": "shell",
    "command": "./build.bat",
    "presentation": {
        "reveal": "always",
        "panel": "new"
    },
    "problemMatcher": [],
    "group": {
        "kind": "build",
        "isDefault": true
    }
}

Upvotes: 6

Views: 6641

Answers (2)

Tiago Ávila
Tiago Ávila

Reputation: 2867

I used the above answer with a few changes to run a task where I wanted to open cmd and after run a command, in my case, I wanted to run iex -S mix phx.server to run my Phoenix app inside IEx (Interactive Elixir).

So here's what I did, in the tasks.json:

{
  "label": "task name",
  "type": "shell",
  "command": "Start-Process",
  "args": [
    "-FilePath",
    "C:/WINDOWS/System32/cmd.exe",
    "-ArgumentList",
    "/K iex -S mix phx.server"
  ],
  "options": {
    "cwd": "${workspaceRoot}",
    "requireFiles": [],
  },
  "presentation": {
    "reveal": "never"
  },
},

I just put in the command property the "Start-Process" and all the remaining things I added as args. The command you want to execute after opening the external terminal must go into the -ArgumentList parameter

Upvotes: 0

VagrantAI
VagrantAI

Reputation: 670

tasks.json version 2.0.0 edit:

{
    "label": "%name%",
    "type": "shell",
    "command": "Start-Process -FilePath \"%path to bat%\"",
    "presentation": {
        "reveal": "never"
    },
    "problemMatcher": [],
    "group": {
        "kind": "build",
        "isDefault": true
    }
},

For older tasks.json version: So, while vscode uses PowerShell as main environment on windows, next piece worked for me:

"command": "Start-Process -FilePath \"path to script\"",
"presentation": {
    "reveal": "never"
},

Upvotes: 3

Related Questions