【问题标题】:How to run a script in a new Integrated Terminal window from an Integrated Terminal window如何从集成终端窗口在新的集成终端窗口中运行脚本
【发布时间】:2019-06-03 15:44:09
【问题描述】:

通常我在一个集成终端中运行一组命令,然后打开另一个并在该终端中运行我的另一组命令。

我想运行一个 Bash/PowerShell 脚本,在 Visual Studio Code 中运行这两个脚本,在它们自己的集成终端中,在同一个 VS Code 实例中。

这可能吗?

差不多 2 年前的这个问题提出了同样的问题,但没有答案:What's the command to open a new integrated terminal from within the integrated terminal in vscode?

【问题讨论】:

    标签: bash powershell visual-studio-code


    【解决方案1】:

    您可以根据自己的选择同时打开任意数量的终端,只需单击加号或使用链接中注明的热键,然后单击该拆分终端图标或使用它的热键 (CTL+)。

    您当然可以添加自己的键绑定来帮助使用多个终端,例如,将它们添加到您的 keybindings.json 文件中,以便对终端进行额外的键盘导航。

    [
    { "key": "ctrl+shift+x", "command": "workbench.action.terminal.kill" },
    { "key": "ctrl+shift+j", "command": "workbench.action.terminal.focusNext" },
    { "key": "ctrl+shift+k", "command": "workbench.action.terminal.focusPrevious" },
    ]
    

    以及本文作者展示的其他选项。 Mastering VS Code's Terminal

    然而,您似乎在说,您想运行脚本并让它自动打开一个新终端并自动拆分屏幕以运行该新终端的段。您可能最接近的方法是使用 VSC 文档和本文中所述的 VSC 任务:

    Visual Studio Code Tasks and Split Terminals

    {
        "label": "Run Server",
        "type": "shell",
        "command": "${config:python.pythonPath} manage.py runserver --noreload",
        "presentation": {
            "group": "groupServerStuff"
        }
    },
    

    同一组的所有任务将作为另一个拆分终端打开 同一终端窗口中的窗格。很不错。

    不是单独开始每个任务,有没有办法让任务 “调用”或“生成”其他任务...

    {
        "label": "Run Server",
        "dependsOn": [
            "Run TCP Server",
            "Run Django Server",
            "Tail Log File"
        ]
    },
    {
        "label": "Run Django Server",
        "type": "shell",
        "command": "${config:python.pythonPath} manage.py runserver --noreload",
        "presentation": {
            "group": "groupServerStuff"
        }
    },
    {
        "label": "Run TCP Server",
        "type": "shell",
        "command": "${config:python.pythonPath} scripts/tcp_server.py",
        "presentation": {
            "group": "groupServerStuff"
        }
    },
    {
        "label": "Tail Log File",
        "type": "shell",
        "command": "tail -f /tmp/logfile.txt",
        "presentation": {
            "group": "groupServerStuff"
        }
    },
    

    【讨论】:

    • 我没有得到预期的结果。我只是看到如下输出:> Executing task: '.\Powershell Launch Scripts\launchFrontend.ps1' < .\Powershell Launch Scripts\launchFrontend.ps1 Terminal will be reused by tasks, press any key to close it.command"'.\\Powershell Launch Scripts\\launchFrontend.ps1'"。我得深入研究一下。
    • 很晚了,但是关于这篇文章的通知让我回来了,并鼓励我再试一次,它有效!谢谢你的例子。我唯一真正改变的是让我的command 等于"npm run serve --prefix '${workspaceFolder}/locationOfMyFrontendProject'"
    • 不用担心,很高兴知道它对您有所帮助,并且您的 npm 也能正常工作。
    猜你喜欢
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 2015-08-15
    • 2021-01-26
    • 2018-05-08
    • 2013-10-18
    相关资源
    最近更新 更多