Currently, the SetEnvironmentVariable action applies globally. Consider the following launch file:
import launch
from launch.actions import GroupAction
from launch.actions import ExecuteProcess
from launch.actions import SetEnvironmentVariable
def generate_launch_description():
return launch.LaunchDescription([
SetEnvironmentVariable(name='my_env_var', value='1'),
ExecuteProcess(cmd=['echo', '$my_env_var'], output='screen', shell=True),
GroupAction([
SetEnvironmentVariable(name='my_env_var', value='2'),
]),
])
Though I would expect it to output 1, it actually outputs 2.
My expectation is similar to what is described in the XML launch file design doc. Note, front-end launch files inherit the same behavior has the above Python example.
Implementation considerations
FWIW, I noticed that using the EnvironmentVariable substitution works as expected. For example,
import launch
from launch.actions import GroupAction
from launch.actions import ExecuteProcess
from launch.actions import SetEnvironmentVariable
from launch.substitutions import EnvironmentVariable
def generate_launch_description():
return launch.LaunchDescription([
SetEnvironmentVariable(name='my_env_var', value='1'),
ExecuteProcess(cmd=['echo', EnvironmentVariable('my_env_var')], output='screen')
GroupAction([
SetEnvironmentVariable(name='my_env_var', value='2'),
]),
])
outputs 1 as I would expect. So, it seems the issue is specific to processes.
Feature request
Feature description
Currently, the
SetEnvironmentVariable
action applies globally. Consider the following launch file:Though I would expect it to output
1
, it actually outputs2
.My expectation is similar to what is described in the XML launch file design doc. Note, front-end launch files inherit the same behavior has the above Python example.
Implementation considerations
FWIW, I noticed that using the
EnvironmentVariable
substitution works as expected. For example,outputs
1
as I would expect. So, it seems the issue is specific to processes.