【问题标题】:Can preLaunchTask and launch start within the same terminal in VSCode?preLaunchTask 和 launch 可以在 VSCode 的同一个终端中启动吗?
【发布时间】:2019-12-22 09:32:21
【问题描述】:

我正在使用 VSCode 调试我的 CPP 代码。在我的代码运行之前,我需要使用 preLaunchTask 来设置我的环境。所以我的代码应该在同一个终端中的 preLaunchTask 之后运行。但它现在从两个不同的终端开始。我该怎么办?

顺便说一句,我下次如何在同一个终端中启动该进程?一些进程下次会启动另一个终端,我很困惑。

我的 preLaunchTask:

{
    "label": "source_setup",
    "type": "shell",
    "command": "source ./devel/setup.zsh && export ROS_MASTER_URI=http://localhost:11311/ "
},

【问题讨论】:

    标签: c++ debugging visual-studio-code vscode-tasks


    【解决方案1】:

    正如@isidorn 在此vscode GitHub issue 中所述,此功能目前尚不支持。同时,人们可以通过将以下代码添加到他们的.bashrc来实现所需的行为

    # Source ros setup.bash if present
    if [ -f '../devel/setup.bash' ]; then . "../devel/setup.bash";fi
    

    【讨论】:

      【解决方案2】:

      如果您不想在任务运行后手动切换到终端,这里有一个很好的解决方法:

      将此行添加到您的 launch.json 配置中:

      "internalConsoleOptions": "openOnSessionStart"
      

      一旦任务脚本完成运行,这将切换到终端视图。

      【讨论】:

        【解决方案3】:

        我认为你可以只使用envFile 属性。

        在我的例子中,启动调试看起来像这样(这个是 python 使用的,但在运行之前它还需要采购./devel/setup.bash):

        {
            "version": "0.2.0",
            "configurations": [
                {
                    "name": "Python: Current ROS File",
                    "type": "python",
                    "request": "launch",
                    "program": "${file}",
                    "console": "integratedTerminal",
                    "envFile": "${workspaceFolder}/devel/setup.bash"
                }
            ]
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-09-07
          • 2020-11-13
          • 2022-10-16
          • 1970-01-01
          • 2021-11-07
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多