-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Adding the opposite function of shlex.split() #66644
Comments
There is currently shlex.split() that is for example useful to split a command string and pass it to subprocess.Popen with shell=False. But I'm missing a function that does the opposite: Building the command string from a list that could for example then be used in subprocess.Popen with shell=True. |
' '.join(shlex.quote(x) for x in split_command) |
Yes, it is possible to do this with a few other commands. But I think it would be still a nice enhancement to have a direct function for it. |
For the record I am on board with a shlex.join. Even though the implementation is simple:
|
Hi Vinay, You made the most recent changes to shlex, so I was wondering what you thought of this suggestion. Thanks! |
I like it, myself, though there is some danger in promoting the idea that this is a "safe" operation. It theoretically should be, but it increases the attack surface slightly if you actually use it (that is, using shell=False is always safer, by at least a small margin). Maybe a mention of that in the docs would be enough, though. |
I'm +0 on the idea. |
One usecase that such a function would be well-suited for is for *displaying* commands being executed. Then, the commands will be executed as a command+args array, but can be displayed unambiguously in log output. |
I am interested in shlex.join as a way to log subprocess.CompletedProcess.args as a string that users could run in their terminals. I initially assumed that this was also the scope of shlex.join. However, it seems that shlex.join does not accept all types of command arguments supported by subprocess, such as pathlib.Path objects. Should shlex.join support an split_command list that includes pathlib.Path objects and any other types supported by subprocess? |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: