summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjm.bardallo <juanmanuel.bardallo@sic.uhu.es>2019-05-27 10:48:30 +0200
committerjm.bardallo <juanmanuel.bardallo@sic.uhu.es>2019-05-27 10:48:30 +0200
commit588700ab60d54da52d51a0a415b9725128635622 (patch)
tree19434afc42f0f6cf69bc8d9db4a5749579651d68
parent855e3c0247721ad4b1ce323f2505cd27a3534678 (diff)
Bug fixed when out and err are None in operation exec_command
-rw-r--r--admin/Sources/Clients/ogagent/src/opengnsys/oglive/operations.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/admin/Sources/Clients/ogagent/src/opengnsys/oglive/operations.py b/admin/Sources/Clients/ogagent/src/opengnsys/oglive/operations.py
index 9ec907c1..8c74f747 100644
--- a/admin/Sources/Clients/ogagent/src/opengnsys/oglive/operations.py
+++ b/admin/Sources/Clients/ogagent/src/opengnsys/oglive/operations.py
@@ -41,6 +41,7 @@ import array
import six
import chardet
from opengnsys import utils
+from opengnsys.log import logger
def _getMacAddr(ifname):
@@ -209,9 +210,20 @@ def exec_command(cmd):
"""
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = proc.communicate()
+ try:
+ if out is not None:
+ encoding = chardet.detect(out)["encoding"]
+ if encoding is not None:
+ out = out.decode(encoding).encode("utf8")
+ if err is not None:
+ encoding = chardet.detect(err)["encoding"]
+ if encoding is not None:
+ err = err.decode(encoding).encode("utf8")
+ except Exception as e:
+ logger.debug("ERROR EXEC COMMAND: {}".format(str(e)))
+
stat = proc.returncode
- return stat, out.decode(chardet.detect(out)['encoding']).encode('utf8'),\
- err.decode(chardet.detect(err)['encoding']).encode('utf8')
+ return stat, out, err
def get_hardware():