2014-04-18 20:31:22 +02:00
|
|
|
# Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
|
|
|
|
# reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
# can be found in the LICENSE file
|
|
|
|
|
2020-01-09 15:42:00 +01:00
|
|
|
from __future__ import absolute_import
|
2014-04-18 20:31:22 +02:00
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
import sys
|
|
|
|
|
2017-05-28 15:04:18 +02:00
|
|
|
|
2017-04-27 03:59:52 +02:00
|
|
|
def exec_cmd(cmd, path, input_string=None):
|
2014-04-18 20:31:22 +02:00
|
|
|
""" Execute the specified command and return the result. """
|
|
|
|
out = ''
|
|
|
|
err = ''
|
2019-05-15 16:35:41 +02:00
|
|
|
ret = -1
|
2014-04-18 20:31:22 +02:00
|
|
|
parts = cmd.split()
|
|
|
|
try:
|
2017-04-27 03:59:52 +02:00
|
|
|
if input_string is None:
|
2017-05-28 15:04:18 +02:00
|
|
|
process = Popen(
|
|
|
|
parts,
|
|
|
|
cwd=path,
|
|
|
|
stdout=PIPE,
|
|
|
|
stderr=PIPE,
|
|
|
|
shell=(sys.platform == 'win32'))
|
2017-04-27 03:59:52 +02:00
|
|
|
out, err = process.communicate()
|
2019-05-15 16:35:41 +02:00
|
|
|
ret = process.returncode
|
2014-05-02 22:57:30 +02:00
|
|
|
else:
|
2017-05-28 15:04:18 +02:00
|
|
|
process = Popen(
|
|
|
|
parts,
|
|
|
|
cwd=path,
|
|
|
|
stdin=PIPE,
|
|
|
|
stdout=PIPE,
|
|
|
|
stderr=PIPE,
|
|
|
|
shell=(sys.platform == 'win32'))
|
2017-04-27 03:59:52 +02:00
|
|
|
out, err = process.communicate(input=input_string)
|
2019-05-15 16:35:41 +02:00
|
|
|
ret = process.returncode
|
2020-01-09 15:42:00 +01:00
|
|
|
except IOError as e:
|
|
|
|
(errno, strerror) = e.args
|
2014-04-18 20:31:22 +02:00
|
|
|
raise
|
|
|
|
except:
|
|
|
|
raise
|
2020-01-09 16:08:24 +01:00
|
|
|
return {'out': out.decode('utf-8'), 'err': err.decode('utf-8'), 'ret': ret}
|