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.
This commit is contained in:
Cas Cremers 2013-12-09 09:07:47 +00:00
parent 1a9b494f85
commit 7e3f0ed73b

View File

@ -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()