in remove-apache-license-identifier.py [0:0]
def run(cmd, cwd=None, encoding=None):
"""Run a command in a subshell and return the standard output.
Run the command cmd in the directory cwd and use encoding to
decode the standard output.
"""
kwds = {
'cwd': cwd,
'stdout': subprocess.PIPE,
'stderr': subprocess.PIPE,
'text': True,
}
if sys.version_info >= (3, 6): # encoding introduced in Python 3.6
kwds['encoding'] = encoding
logging.debug('Running "%s" in %s', ' '.join(cmd), cwd)
result = subprocess.run(cmd, **kwds, check=False)
if result.returncode:
logging.debug('Failed command: %s', ' '.join(cmd))
logging.debug('Failed return code: %s', result.returncode)
logging.debug('Failed stdout: %s', result.stdout.strip())
logging.debug('Failed stderr: %s', result.stderr.strip())
return []
# Remove line continuations before splitting stdout into lines
# Running command with text=True converts line endings to \n in stdout
lines = result.stdout.replace('\\\n', ' ').splitlines()
return [strip_whitespace(line) for line in lines]