diff --git a/common/command.py b/common/command.py index a5767b2ab4428da768ad993cb0f04d88d82f6cf2..6e2e4334441a13487d3ec072748256f13b28ca9a 100644 --- a/common/command.py +++ b/common/command.py @@ -98,5 +98,26 @@ class Command: except Exception as err: Logger().error("An exception occurred when executing [{}]: {}".format(cmd, err)) return command_result - - \ No newline at end of file + + + @staticmethod + def cmd_exec_err(cmd, caller = ''): + ''' + Encapsulate the general RUN function, get the result + ''' + command_result = '' + try: + env_c = os.environ + env_c['LANG'] = 'en_US.UTF-8' + # ret = subprocess.run(cmd, shell = True, stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env_c) + ret = subprocess.Popen(cmd, shell = True, stdout = subprocess.PIPE , stderr = subprocess.PIPE, env = env_c) + stdout,stderr = ret.communicate() + if Command.cmd_check(stdout, stderr, ret.returncode, cmd): + command_result = stderr.decode('utf8') + return command_result + + except Exception as err: + Logger().error("An exception occurred when executing [{}]: {}".format(cmd, err)) + return command_result + + \ No newline at end of file