|
84 | 84 |
|
85 | 85 | @expose_action('executable') |
86 | 86 | class ExecuteProcess(Action): |
87 | | - """Action that begins executing a process and sets up event handlers for the process.""" |
| 87 | + """ |
| 88 | + Action that begins executing a process and sets up event handlers for it. |
| 89 | +
|
| 90 | + Simple example: |
| 91 | +
|
| 92 | + .. doctest:: |
| 93 | +
|
| 94 | + >>> ld = LaunchDescription([ |
| 95 | + ... ExecuteProcess( |
| 96 | + ... cmd=['ls', '-las'], |
| 97 | + ... name='my_ls_process', # this is optional |
| 98 | + ... output='both', |
| 99 | + ... ), |
| 100 | + ... ]) |
| 101 | +
|
| 102 | + .. code-block:: xml |
| 103 | +
|
| 104 | + <launch> |
| 105 | + <executable cmd="ls -las" name="my_ls_process" output="both"/> |
| 106 | + </launch> |
| 107 | +
|
| 108 | + Substitutions in the command: |
| 109 | +
|
| 110 | + .. doctest:: |
| 111 | +
|
| 112 | + >>> ld = LaunchDescription([ |
| 113 | + ... DeclareLaunchArgument(name='file_path', description='file path to cat'), |
| 114 | + ... ExecuteProcess( |
| 115 | + ... # each item of the command arguments' list can be: |
| 116 | + ... # a string ('cat'), |
| 117 | + ... # a substitution (`LaunchConfiguration('file_path')`), |
| 118 | + ... # or a list of string/substitutions |
| 119 | + ... # (`[LaunchConfiguration('directory'), '/file.txt']`) |
| 120 | + ... cmd=['cat', LaunchConfiguration('file_path')], |
| 121 | + ... ), |
| 122 | + ... ]) |
| 123 | +
|
| 124 | + .. code-block:: xml |
| 125 | +
|
| 126 | + <launch> |
| 127 | + <arg name="file_path" description="path of the file to cat"/> |
| 128 | + <executable cmd="cat $(var file_path)"/> |
| 129 | + </launch> |
| 130 | +
|
| 131 | + Optional cli argument: |
| 132 | +
|
| 133 | + .. doctest:: |
| 134 | +
|
| 135 | + >>> ld = LaunchDescription([ |
| 136 | + ... DeclareLaunchArgument(name='open_gui', default_value='False'), |
| 137 | + ... ExecuteProcess( |
| 138 | + ... cmd=['my_cmd', '--open-gui'], |
| 139 | + ... condition=IfCondition(LaunchConfiguration('open_gui')), |
| 140 | + ... ), |
| 141 | + ... ExecuteProcess( |
| 142 | + ... cmd=['my_cmd'], |
| 143 | + ... condition=UnlessCondition(LaunchConfiguration('open_gui')), |
| 144 | + ... ), |
| 145 | + ... ]) |
| 146 | +
|
| 147 | + .. code-block:: xml |
| 148 | +
|
| 149 | + <launch> |
| 150 | + <arg name="open_gui" description="when truthy, the gui will be opened"/> |
| 151 | + <executable cmd="my_cmd --open-gui" if="$(var open_gui)"/> |
| 152 | + <executable cmd="my_cmd" unless="$(var open_gui)"/> |
| 153 | + </launch> |
| 154 | +
|
| 155 | + Environment variables: |
| 156 | +
|
| 157 | + .. doctest:: |
| 158 | +
|
| 159 | + >>> ld = LaunchDescription([ |
| 160 | + ... ExecuteProcess( |
| 161 | + ... cmd=['my_cmd'], |
| 162 | + ... additional_env={'env_variable': 'env_var_value'}, |
| 163 | + ... ), |
| 164 | + ... ]) |
| 165 | +
|
| 166 | + .. code-block:: xml |
| 167 | +
|
| 168 | + <launch> |
| 169 | + <executable cmd="my_cmd"> |
| 170 | + <env name="env_variable" value="env_var_value"/> |
| 171 | + </executable> |
| 172 | + </launch> |
| 173 | + """ |
88 | 174 |
|
89 | 175 | def __init__( |
90 | 176 | self, |
|
0 commit comments