From 2ac6daa3f5931870f968ea31ba6d76e2c28e2e64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20M=2E=20G=C3=B3mez?= Date: Thu, 23 May 2019 14:29:08 +0200 Subject: [PATCH] #908: Trying to fix a bug when obteining execution outputs. --- src/opengnsys/modules/server/OpenGnSys/__init__.py | 3 +-- src/opengnsys/oglive/operations.py | 4 +++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/opengnsys/modules/server/OpenGnSys/__init__.py b/src/opengnsys/modules/server/OpenGnSys/__init__.py index bc9909f..40347f4 100644 --- a/src/opengnsys/modules/server/OpenGnSys/__init__.py +++ b/src/opengnsys/modules/server/OpenGnSys/__init__.py @@ -156,8 +156,7 @@ class OpenGnSysWorker(ServerWorker): route = route[len(self.REST.endpoint):] # Send back exit status and outputs (base64-encoded) self.REST.sendMessage(route, {'mac': self.interface.mac, 'ip': self.interface.ip, 'trace': op_id, - 'status': stat, 'output': out.encode('utf8').encode('base64'), - 'error': err.encode('utf8').encode('base64')}) + 'status': stat, 'output': out.encode('base64'), 'error': err.encode('base64')}) # Show latest menu, if OGAgent runs on ogLive if os_type == 'oglive': # Send configuration data, if needed diff --git a/src/opengnsys/oglive/operations.py b/src/opengnsys/oglive/operations.py index 3cdeef0..9ec907c 100644 --- a/src/opengnsys/oglive/operations.py +++ b/src/opengnsys/oglive/operations.py @@ -39,6 +39,7 @@ import subprocess import struct import array import six +import chardet from opengnsys import utils @@ -209,7 +210,8 @@ def exec_command(cmd): proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = proc.communicate() stat = proc.returncode - return stat, out, err + return stat, out.decode(chardet.detect(out)['encoding']).encode('utf8'),\ + err.decode(chardet.detect(err)['encoding']).encode('utf8') def get_hardware():