windows 通过tasks 2.0.0在外部终端中启动vscode任务

vmpqdwk3  于 8个月前  发布在  Windows
关注(0)|答案(2)|浏览(107)

是否可以通过外部终端启动bat文件,而不是在vscode终端内?
任务示例:

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

qyswt5oh1#

tasks.json 2.0.0版本编辑:

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

对于较旧的tasks.json版本:所以,虽然vscode使用PowerShell作为Windows上的主要环境,但下一个部分对我来说很有效:

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

lnvxswe22#

我使用了上面的答案,并做了一些修改来运行一个任务,我想打开cmd,然后运行一个命令,在我的例子中,我想运行iex -S mix phx.server来运行我的Phoenix应用程序在IEx(交互式Elixir)中。
下面是我在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"
  },
},

我只是在command属性中添加了“Start-Process”和所有其他我添加为args的东西。打开外部终端后要执行的命令必须进入-ArgumentList参数

相关问题