diff options
-rwxr-xr-x | repo | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -363,15 +363,23 @@ def run_command(cmd, **kwargs): | |||
363 | kwargs.setdefault('stderr', subprocess.PIPE) | 363 | kwargs.setdefault('stderr', subprocess.PIPE) |
364 | cmd_input = kwargs.pop('input', None) | 364 | cmd_input = kwargs.pop('input', None) |
365 | 365 | ||
366 | def decode(output): | ||
367 | """Decode |output| to text.""" | ||
368 | if output is None: | ||
369 | return output | ||
370 | try: | ||
371 | return output.decode('utf-8') | ||
372 | except UnicodeError: | ||
373 | print('repo: warning: Invalid UTF-8 output:\ncmd: %r\n%r' % (cmd, output), | ||
374 | file=sys.stderr) | ||
375 | # TODO(vapier): Once we require Python 3, use 'backslashreplace'. | ||
376 | return output.decode('utf-8', 'replace') | ||
377 | |||
366 | # Run & package the results. | 378 | # Run & package the results. |
367 | proc = subprocess.Popen(cmd, **kwargs) | 379 | proc = subprocess.Popen(cmd, **kwargs) |
368 | (stdout, stderr) = proc.communicate(input=cmd_input) | 380 | (stdout, stderr) = proc.communicate(input=cmd_input) |
369 | if stdout is not None: | ||
370 | stdout = stdout.decode('utf-8') | ||
371 | if stderr is not None: | ||
372 | stderr = stderr.decode('utf-8') | ||
373 | trace.print(':', ' '.join(cmd)) | 381 | trace.print(':', ' '.join(cmd)) |
374 | ret = RunResult(proc.returncode, stdout, stderr) | 382 | ret = RunResult(proc.returncode, decode(stdout), decode(stderr)) |
375 | 383 | ||
376 | # If things failed, print useful debugging output. | 384 | # If things failed, print useful debugging output. |
377 | if check and ret.returncode: | 385 | if check and ret.returncode: |