13

I am debugging my CPP code with VSCode. I need to use a preLaunchTask to set my environment before my code run. So my code should run after preLaunchTask right in the same terminal. But it start in two different terminal now. How can I do with this?

And btw how can I start the process in the same terminal next time? Some process will start another terminal next time, I am confuse.

My preLaunchTask:

{
    "label": "source_setup",
    "type": "shell",
    "command": "source ./devel/setup.zsh && export ROS_MASTER_URI=http://localhost:11311/ "
},
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
HaoQChen
  • 131
  • 3

3 Answers3

4

As stated by @isidorn in this vscode GitHub issue this feature is currently not yet supported. In the meantime, people can achieve the desired behaviour by adding the following code to their .bashrc

# Source ros setup.bash if present
if [ -f '../devel/setup.bash' ]; then . "../devel/setup.bash";fi
rickstaa
  • 405
  • 5
  • 23
0

If you don't want to manually switch to the terminal once the task has ran, here is a good workaround:

add this line to your launch.json config:

"internalConsoleOptions": "openOnSessionStart"

This will switch to the terminal view once the task script has finished running.

TOPKAT
  • 6,667
  • 2
  • 44
  • 72
0

I think you could just use envFile property.

In my case launch for debugging looks like this (this one is used by python, but it also needs sourcing ./devel/setup.bash before running):

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