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

6

是否可以通过外部终端而非在VSCode终端内运行.bat文件?

任务示例:

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

3

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文件: 在Windows系统下,虽然VS Code使用PowerShell作为主要环境,但以下方法可以帮助解决问题:

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

你好,能否详细说明一下是什么让你的进程在外部终端中打开?谢谢 :) 看起来你的答案只适用于Windows操作系统。 - TOPKAT
@538ROMEO 没错,答案基于 PowerShell,这是专属于 Windows 环境的。 - VagrantAI
嗯,尝试执行一个EXE文件时似乎没有起作用。它只是打开了集成终端而不是新窗口。 - rboy

0
我使用上面的答案并进行了一些修改,以便运行一个任务。在这个任务中,我想要打开命令提示符并运行一个命令。在我的情况下,我想要运行iex -S mix phx.server来在IEx(交互式Elixir)中运行我的Phoenix应用程序。
所以这是我在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参数中。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接