Skip to content

Commit bbbda21

Browse files
committed
Enhance command execution by adding shell usage configuration and support for argument splitting
1 parent 5d3587b commit bbbda21

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

sling/sling/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os, sys, tempfile, uuid, json, traceback, subprocess, csv, warnings, io, datetime
1+
import os, sys, tempfile, uuid, json, traceback, subprocess, csv, warnings, io, datetime, shlex
22
from subprocess import PIPE, Popen, STDOUT
33
from typing import Iterable, List, Union, Dict, Any, Optional, IO
44
from json import JSONEncoder
@@ -503,8 +503,11 @@ def _exec_cmd(
503503
if is_package(pkg):
504504
env["SLING_PACKAGE"] = pkg
505505

506+
use_shell = os.environ.get('SLING_PYTHON_USE_SHELL', 'true').lower() != 'false'
507+
cmd_args = cmd if use_shell else shlex.split(cmd)
508+
506509
with Popen(
507-
cmd, shell=True, env=env, stdin=stdin, stdout=stdout, stderr=stderr
510+
cmd_args, shell=use_shell, env=env, stdin=stdin, stdout=stdout, stderr=stderr
508511
) as proc:
509512
if stdout and stdout != STDOUT and proc.stdout:
510513
for line in proc.stdout:

0 commit comments

Comments
 (0)