Ask Your Question

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

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

tlaci gravatar image

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

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 ( :

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

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

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



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

Dirk Thomas gravatar image Dirk Thomas  ( 2020-02-10 10:20:27 -0500 )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



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

Seen: 292 times

Last updated: Feb 10 '20