diff options
author | 2020-02-04 11:51:18 -0800 | |
---|---|---|
committer | 2020-02-04 11:51:18 -0800 | |
commit | 53cb4f7935e858712edea7b2b09ad8b1c75aacd0 (patch) | |
tree | cec0f5b6d6d20217d0fd8386f1a4968376f6a18d /infra/utils.py | |
parent | da04f5e431506443847662a22d820078764a182a (diff) |
[Infra] Update execute function in utils.py (#3319)
Diffstat (limited to 'infra/utils.py')
-rw-r--r-- | infra/utils.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/infra/utils.py b/infra/utils.py index 8f0e4e28..468438f4 100644 --- a/infra/utils.py +++ b/infra/utils.py @@ -13,6 +13,7 @@ # limitations under the License. """Utilities for OSS-Fuzz infrastructure.""" +import logging import os import re import stat @@ -41,7 +42,7 @@ def execute(command, location=None, check_result=False): check_result: Should an exception be thrown on failed command. Returns: - The stdout of the command, the error code. + stdout, stderr, error code. Raises: RuntimeError: running a command resulted in an error. @@ -49,14 +50,20 @@ def execute(command, location=None, check_result=False): if not location: location = os.getcwd() - process = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=location) + process = subprocess.Popen(command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=location) out, err = process.communicate() - if check_result and (process.returncode or err): - raise RuntimeError('Error: %s\n Command: %s\n Return code: %s\n Out: %s' % - (err, command, process.returncode, out)) - if out is not None: - out = out.decode('ascii').rstrip() - return out, process.returncode + out = out.decode('ascii') + err = err.decode('ascii') + if err: + logging.debug('Stderr of command \'%s\' is %s.', ' '.join(command), err) + if check_result and process.returncode: + raise RuntimeError( + 'Executing command \'{0}\' failed with error: {1}.'.format( + ' '.join(command), err)) + return out, err, process.returncode def get_fuzz_targets(path): |