Fix subprocess.Popen: change command to string when shell=True - #191
Open
j-gruen wants to merge 1 commit into
Open
Fix subprocess.Popen: change command to string when shell=True#191j-gruen wants to merge 1 commit into
j-gruen wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
When calling
robolink.Robolinkfrom the Python API on Linux, withrobodk_pathpointing to theRoboDK/RoboDK-Start.shscript, command-line arguments aren't passed to the script.Minimal Example
Reason
The relevant code section is in
Python/robodk/robolink.py, lines 1420-1421:At this point in the code,
commandis an array of form[robodk_path, arg1, arg2, ...].From the docs for subprocess.Popen:
Therefore the call to subprocess.Popen invokes the robodk_path script, but the arguments are passed to the shell and not the script.
Solution
The solution implemented in this PR uses
shlex.jointo convert the command to a string in this specific branch.A secondary solution could be to fully remove this if statement, at which point the program would fall through to lines 1432-1433:
This would still launch the .sh script correctly, providing that it has a proper shebang (the default RoboDK-Start.sh has
#!/bin/sh). However it looks like someone somewhen decided to force /bin/bash as shell through the if statement in lines 1420-1421 for some reason, which this secondary solution would not do.