ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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

Comments

2

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

I thought SetEnvironmentVariable is part of the EnvironmentVariable module but it has to be imported as follows: from launch.actions import SetEnvironmentVariable

Jasmin gravatar image Jasmin  ( 2022-02-13 21:23:47 -0500 )edit

Question Tools

2 followers

Stats

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

Seen: 1,830 times

Last updated: Feb 10 '20