From 8dc7b80bd34223cb872710189c6060996ed10d11 Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Tue, 27 Oct 2020 22:11:51 +0100 Subject: [PATCH] Modernising some of the shell command execute code. --- gui/Scyther/Misc.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/gui/Scyther/Misc.py b/gui/Scyther/Misc.py index e3958a9..6e07098 100644 --- a/gui/Scyther/Misc.py +++ b/gui/Scyther/Misc.py @@ -93,21 +93,19 @@ def getShell(): """ Determine if we want a shell for Popen """ - if sys.platform.startswith("win"): - shell=False - else: - # Needed to handle the string input correctly (as opposed to a sequence where the first element is the executable) - # This is not needed on Windows, where it has a different effect altogether. - # See http://docs.python.org/library/subprocess.html?highlight=subprocess#module-subprocess - shell=True - return shell + return False def safeCommandOutput(cmd, storePopen=None): """ Execute a command and return (sts,sout,serr). Meant for short outputs, as output is stored in memory and not written to a file. """ - p = Popen(cmd, shell=getShell(), stdout=PIPE, stderr=PIPE) + + if isinstance(cmd, str): + import shlex + cmd = shlex.split(cmd) + + p = Popen(cmd, stdout=PIPE, stderr=PIPE) if storePopen != None: storePopen(p) (sout,serr) = p.communicate() @@ -119,7 +117,11 @@ def safeCommand(cmd, storePopen=None): version, I hope. """ try: - p = Popen(cmd, shell=getShell()) + if isinstance(cmd, str): + import shlex + cmd = shlex.split(cmd) + + p = Popen(cmd) if storePopen != None: storePopen(p) sts = p.wait()