From b1a724fa2630c65953bc88d36a7d98401970283e Mon Sep 17 00:00:00 2001 From: Dimitri Merejkowsky Date: Tue, 11 Apr 2017 12:03:44 +0200 Subject: [PATCH] fix running subprocess.run() with shell=True and args being a list --- Lib/subprocess.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 76c340c87970aa..3342550e8f3156 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -47,6 +47,7 @@ import io import os import time +import shlex import signal import builtins import warnings @@ -1209,7 +1210,8 @@ def _execute_child(self, args, executable, preexec_fn, close_fds, # On Android the default shell is at '/system/bin/sh'. unix_shell = ('/system/bin/sh' if hasattr(sys, 'getandroidapilevel') else '/bin/sh') - args = [unix_shell, "-c"] + args + cmdline = " ".join(shlex.quote(x) for x in args) + args = [unix_shell, "-c", cmdline] if executable: args[0] = executable