Skip to content

Commit 0c5a017

Browse files
committed
fix posix logic and add test
Signed-off-by: William Woodall <[email protected]>
1 parent c75ccf4 commit 0c5a017

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

launch/launch/actions/execute_local.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ def execute(self, context: LaunchContext) -> Optional[List[LaunchDescriptionEnti
759759
expanded_cmd = []
760760
assert self.__process_event_args is not None
761761
for token in self.__process_event_args['cmd']:
762-
expanded_cmd.extend(shlex.split(token, posix=g_is_windows))
762+
expanded_cmd.extend(shlex.split(token, posix=(not g_is_windows)))
763763
# Also update self.__process_event_args['cmd'] so it reflects the splitting.
764764
self.__process_event_args['cmd'] = expanded_cmd
765765
context.asyncio_loop.create_task(self.__execute_process(context))

launch/test/launch/test_execute_process.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424
from launch import LaunchService
2525
from launch.actions import SetLaunchConfiguration
2626
from launch.actions.emit_event import EmitEvent
27+
from launch.actions.execute_local import g_is_windows
2728
from launch.actions.execute_process import ExecuteProcess
2829
from launch.actions.opaque_function import OpaqueFunction
2930
from launch.actions.register_event_handler import RegisterEventHandler
3031
from launch.actions.shutdown_action import Shutdown
3132
from launch.actions.timer_action import TimerAction
33+
from launch.event_handlers.on_process_io import OnProcessIO
3234
from launch.event_handlers.on_process_start import OnProcessStart
35+
from launch.events.process import ProcessIO
3336
from launch.events.shutdown import Shutdown as ShutdownEvent
3437
from launch.substitutions.launch_configuration import LaunchConfiguration
3538

@@ -408,3 +411,39 @@ def test_execute_process_split_arguments_override_in_launch_file():
408411

409412
assert execute_process_action1.return_code == 2, execute_process_action1.process_details['cmd']
410413
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

Comments
 (0)