From e44bbc6c076935a7023f5f2a1b494e548881e637 Mon Sep 17 00:00:00 2001 From: chrys Date: Tue, 18 Oct 2016 22:24:10 +0200 Subject: [PATCH] decode subprocess call correctly --- src/fenrir/commands/commands/subprocess.py | 23 +++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/fenrir/commands/commands/subprocess.py b/src/fenrir/commands/commands/subprocess.py index 9406aeee..06c039c2 100644 --- a/src/fenrir/commands/commands/subprocess.py +++ b/src/fenrir/commands/commands/subprocess.py @@ -28,14 +28,19 @@ class command(): if not os.access(self.scriptPath, os.X_OK): self.env['runtime']['outputManager'].presentText('scriptfile is not executable' , soundIcon='', interrupt=False) return - p = Popen(self.scriptPath , stdout=PIPE, stderr=PIPE, shell=True) - stdout, stderr = p.communicate() - self.env['runtime']['outputManager'].interruptOutput() - stderr = str(stderr) - stdout = str(stdout) - if stderr != '': - self.env['runtime']['outputManager'].presentText(stdout , soundIcon='', interrupt=False) - if stdout != '': - self.env['runtime']['outputManager'].presentText(stdout , soundIcon='', interrupt=False) + try: + p = Popen(self.scriptPath , stdout=PIPE, stderr=PIPE, shell=True) + stdout, stderr = p.communicate() + self.env['runtime']['outputManager'].interruptOutput() + screenEncoding = self.env['runtime']['settingsManager'].getSetting('screen', 'encoding') + stderr = stderr.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') + stdout = stdout.decode(screenEncoding, "replace").encode('utf-8').decode('utf-8') + if stderr != '': + self.env['runtime']['outputManager'].presentText(stdout , soundIcon='', interrupt=False) + if stdout != '': + self.env['runtime']['outputManager'].presentText(stdout , soundIcon='', interrupt=False) + except Exception as e: + self.env['runtime']['outputManager'].presentText(e , soundIcon='', interrupt=False) + def setCallback(self, callback): pass