Launch vscode task in external terminal via tasks 2.0.0
Asked Answered
C

2

6

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
    }
}
Coessential answered 27/12, 2017 at 14:9 Comment(0)
C
3

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"
},
Coessential answered 30/12, 2017 at 11:49 Comment(3)
Hi, could you please elaborate on what makes your process open in an external terminal. Thanks :) It seem your answer will not work on other operating systems than windowsSpeculum
@538ROMEO That is right, answer is based on powershell which is exclusive to windows environmentCoessential
Hmm, it didn't seem to work when trying to execute an EXE file. It just opens the integrated terminal instead of a new windowSanderling
C
0

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

Coddle answered 20/10, 2023 at 13:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.