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
|
|
|
|
|
|
|
|
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
|
2014-04-18 20:31:22 +02:00
|
|
|
except IOError, (errno, strerror):
|
|
|
|
raise
|
|
|
|
except:
|
|
|
|
raise
|
2019-05-15 16:35:41 +02:00
|
|
|
return {'out': out, 'err': err, 'ret': ret}
|