Skip to content

Commit

Permalink
[Windows] Single quote string fix-up (#2051)
Browse files Browse the repository at this point in the history
* add split_with_single_quote_enclosed_fixup

* address feedback.

* revert the renaming.
  • Loading branch information
seanyen authored Oct 5, 2020
1 parent 133b510 commit 089dd64
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions tools/roslaunch/src/roslaunch/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,12 +497,19 @@ def param_value(self, verbose, name, ptype, value, textfile, binfile, command):
if os.name != 'nt':
command = shlex.split(command)
else:
cl = shlex.split(command, posix=False) # use non-posix method on Windows

# On Linux, single quotes are commonly used to enclose a path to escape spaces.
# However, on Windows, the single quotes are treated as part of the arguments.
# Special handling is required to remove the extra single quotes.
if "'" in command:
cl = [token[1:-1] if token.startswith("'") and token.endswith("'") else token for token in cl]
command = cl

# Python scripts in ROS tend to omit .py extension since they could become executable with shebang line
# special handle the use of Python scripts in Windows environment:
# 1. search for a wrapper executable (of the same name) under the same directory with stat.S_IXUSR flag
# 2. if no wrapper is present, prepend command with 'python' executable

cl = shlex.split(command, posix=False) # use non-posix method on Windows
if os.path.isabs(cl[0]):
# trying to launch an executable from a specific location(package), e.g. xacro
import stat
Expand All @@ -527,7 +534,7 @@ def param_value(self, verbose, name, ptype, value, textfile, binfile, command):
if os.path.splitext(f)[1].lower() in ['.py', '']:
executable_command = ' '.join([sys.executable, f])
if executable_command:
command = command.replace(cl[0], executable_command, 1)
command[0] = executable_command
p = subprocess.Popen(command, stdout=subprocess.PIPE)
c_value = p.communicate()[0]
if not isinstance(c_value, str):
Expand Down

0 comments on commit 089dd64

Please sign in to comment.