From 7e3f0ed73b6d3623731fd8c2d264fe1c4a247843 Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Mon, 9 Dec 2013 09:07:47 +0000 Subject: [PATCH] BUGFIX: Reverted use of shlex. Shlex is only intended to work for Unix-like shells, and using it on Windows causes problems. We now resort to simply always using the shell on Unix-like platforms (as our command input is always a string, and not an array). On Windows, the string input is always okay, even when not using the shell. This is a follow-up to a bug report by M. Kammerer on failing Windows installs. --- gui/Scyther/Misc.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/gui/Scyther/Misc.py b/gui/Scyther/Misc.py index 3279039..9ff9725 100644 --- a/gui/Scyther/Misc.py +++ b/gui/Scyther/Misc.py @@ -90,12 +90,25 @@ def mypath(file): basedir = os.path.split(cmd_file)[0] return os.path.join(basedir,file) +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 + 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(shlex.split(cmd), shell=False, stdout=PIPE, stderr=PIPE) + p = Popen(cmd, shell=getShell(), stdout=PIPE, stderr=PIPE) if storePopen != None: storePopen(p) (sout,serr) = p.communicate() @@ -107,7 +120,7 @@ def safeCommand(cmd, storePopen=None): version, I hope. """ try: - p = Popen(shlex.split(cmd), shell=False) + p = Popen(cmd, shell=getShell()) if storePopen != None: storePopen(p) sts = p.wait()