From 3fa09f24ceb44ae75ed7d55df7734d41ee0f066f Mon Sep 17 00:00:00 2001 From: gau1991 Date: Mon, 16 Feb 2015 14:22:37 +0530 Subject: [PATCH] Fixing Unicode error during PHP repo adding --- ee/core/shellexec.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ee/core/shellexec.py b/ee/core/shellexec.py index b70e37d1..1e1553a3 100644 --- a/ee/core/shellexec.py +++ b/ee/core/shellexec.py @@ -1,9 +1,9 @@ """EasyEngine shell executaion functions.""" -from subprocess import Popen from ee.core.logging import Log import os import sys import subprocess +import shlex class EEShellExec(): @@ -16,11 +16,20 @@ class EEShellExec(): try: if log: Log.debug(self, "Running command: {0}".format(command)) - retcode = subprocess.getstatusoutput(command) - if retcode[0] == 0: + args = shlex.split(command) + with subprocess.Popen(args, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) as proc: + (cmd_stdout_bytes, cmd_stderr_bytes) = proc.communicate() + (cmd_stdout, cmd_stderr) = (cmd_stdout_bytes.decode('utf-8', + "replace"), + cmd_stderr_bytes.decode('utf-8', + "replace")) + + if proc.returncode == 0: return True else: - Log.debug(self, retcode[1]) + Log.debug(self, "Command Output: {0}, Command Error: {1}" + .format(cmd_stdout, cmd_stderr)) return False except OSError as e: if errormsg: