Skip to content

Commit 3144471

Browse files
committed
Refactor command execution to support list-based arguments and improve shell usage handling
1 parent 38e32fd commit 3144471

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

sling/sling/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,7 @@ def _run(cmd: str, temp_file: str, return_output=False, env:dict=None, stdin=Non
465465
def cli(*args, return_output=False):
466466
"calls the sling binary with the provided args"
467467
args = args or sys.argv[1:]
468-
escape = lambda a: a.replace('"', '\\"')
469-
cmd = f'''{SLING_BIN} {" ".join([f'"{escape(a)}"' for a in args])}'''
468+
cmd = [SLING_BIN, *args]
470469
lines = []
471470
try:
472471
stdout = PIPE if return_output else sys.stdout
@@ -504,7 +503,10 @@ def _exec_cmd(
504503
env["SLING_PACKAGE"] = pkg
505504

506505
use_shell = os.environ.get('SLING_PYTHON_USE_SHELL', 'false').lower() == 'true'
507-
cmd_args = cmd if use_shell else shlex.split(cmd, posix=(os.name != 'nt'))
506+
if isinstance(cmd, list):
507+
cmd_args = subprocess.list2cmdline(cmd) if use_shell else cmd
508+
else:
509+
cmd_args = cmd if use_shell else shlex.split(cmd, posix=(os.name != 'nt'))
508510

509511
with Popen(
510512
cmd_args, shell=use_shell, env=env, stdin=stdin, stdout=stdout, stderr=stderr

0 commit comments

Comments
 (0)