Ask Your Question
0

[ROS2] extend env vars in launch file instead of overwriting

asked 2020-02-04 04:01:31 -0600

tlaci gravatar image

updated 2020-02-04 04:23:15 -0600

gvdhoorn gravatar image

Hey all,

Is it possible to somehow extend environment instead of overwriting them in a launch file? I need something like this (https://github.com/ros2/launch/issues...) :

SetEnvironmentVariable(name='PATH', value=[EnvironmentVariable('PATH'), '/some/other/bin']

But unfortunately appending is not supported yet EnvironmentVariable gives an error.

It seems to be possible to do it with ExecuteProcess based on this discussion but I do not want to start my node like this even if it is possible.
ExecuteProcess(cmd=cmd, additional_env=env, output='screen')

Also ExecuteProcess(cmd=['export', 'LD_LIBRARY_PATH=<NEW_PATH>:$LD_LIBRARY_PATH'], output='screen'), does not work.

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-02-10 05:56:27 -0600

tlaci gravatar image

My bad, have to import EnvironmentVariable module

from launch.substitutions import EnvironmentVariable

Also the colon must be added manually to append approriately, this works:
SetEnvironmentVariable(name='PATH', value=[EnvironmentVariable('PATH'), ':/some/other/bin']

edit flag offensive delete link more

Comments

1

Note that the hard coded colon makes you launch file platforms specific. You might want to use os.pathsep instead.

Dirk Thomas gravatar imageDirk Thomas ( 2020-02-10 10:20:27 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-02-04 04:01:31 -0600

Seen: 22 times

Last updated: Feb 10