Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Single quote string fix-up #2051

Merged
merged 3 commits into from
Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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