|
24 | 24 | from launch import LaunchService |
25 | 25 | from launch.actions import SetLaunchConfiguration |
26 | 26 | from launch.actions.emit_event import EmitEvent |
| 27 | +from launch.actions.execute_local import g_is_windows |
27 | 28 | from launch.actions.execute_process import ExecuteProcess |
28 | 29 | from launch.actions.opaque_function import OpaqueFunction |
29 | 30 | from launch.actions.register_event_handler import RegisterEventHandler |
30 | 31 | from launch.actions.shutdown_action import Shutdown |
31 | 32 | from launch.actions.timer_action import TimerAction |
| 33 | +from launch.event_handlers.on_process_io import OnProcessIO |
32 | 34 | from launch.event_handlers.on_process_start import OnProcessStart |
| 35 | +from launch.events.process import ProcessIO |
33 | 36 | from launch.events.shutdown import Shutdown as ShutdownEvent |
34 | 37 | from launch.substitutions.launch_configuration import LaunchConfiguration |
35 | 38 |
|
@@ -408,3 +411,39 @@ def test_execute_process_split_arguments_override_in_launch_file(): |
408 | 411 |
|
409 | 412 | assert execute_process_action1.return_code == 2, execute_process_action1.process_details['cmd'] |
410 | 413 | assert execute_process_action2.return_code == 3, execute_process_action2.process_details['cmd'] |
| 414 | + |
| 415 | + |
| 416 | +def test_execute_process_split_arguments_with_windows_like_pathsep(): |
| 417 | + # On POSIX platforms the `\` will be removed, but not on windows. |
| 418 | + path = b'C:\\some\\path' |
| 419 | + execute_process_args = { |
| 420 | + 'cmd': preamble + [f'--some-arg {path.decode()}'], |
| 421 | + 'output': 'screen', |
| 422 | + 'shell': False, |
| 423 | + 'split_arguments': True, |
| 424 | + 'log_cmd': True, |
| 425 | + } |
| 426 | + execute_process_action1 = ExecuteProcess(**execute_process_args) |
| 427 | + |
| 428 | + did_see_path = False |
| 429 | + |
| 430 | + def on_stdout(event: ProcessIO): |
| 431 | + nonlocal did_see_path |
| 432 | + if event.from_stdout and path in event.text: |
| 433 | + did_see_path = True |
| 434 | + |
| 435 | + event_handler = OnProcessIO( |
| 436 | + target_action=execute_process_action1, |
| 437 | + on_stdout=on_stdout, |
| 438 | + ) |
| 439 | + |
| 440 | + ld = LaunchDescription([ |
| 441 | + RegisterEventHandler(event_handler), |
| 442 | + execute_process_action1, |
| 443 | + ]) |
| 444 | + ls = LaunchService() |
| 445 | + ls.include_launch_description(ld) |
| 446 | + assert 0 == ls.run(shutdown_when_idle=True) |
| 447 | + |
| 448 | + assert execute_process_action1.return_code == 3, execute_process_action1.process_details['cmd'] |
| 449 | + assert did_see_path == g_is_windows |
0 commit comments