[ROS2] extend env vars in launch file instead of overwriting
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/164) :
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.
Asked by tlaci on 2020-02-04 05:01:31 UTC
Answers
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']
Asked by tlaci on 2020-02-10 06:56:27 UTC
Comments
Note that the hard coded colon makes you launch file platforms specific. You might want to use os.pathsep
instead.
Asked by Dirk Thomas on 2020-02-10 11:20:27 UTC
I thought SetEnvironmentVariable
is part of the EnvironmentVariable
module but it has to be imported as follows: from launch.actions import SetEnvironmentVariable
Asked by Jasmin on 2022-02-13 22:23:47 UTC
Comments