merge_output.py 702 B

1234567891011121314151617181920212223242526272829
  1. """Merges stdout and stderr into a single stream with labels."""
  2. __copyright__ = """
  3. Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  4. Exceptions. See /LICENSE for license information.
  5. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. """
  7. import subprocess
  8. import sys
  9. import textwrap
  10. def main() -> None:
  11. p = subprocess.run(
  12. sys.argv[1:],
  13. stdout=subprocess.PIPE,
  14. stderr=subprocess.PIPE,
  15. encoding="utf-8",
  16. )
  17. if p.stdout:
  18. print(textwrap.indent(p.stdout, "STDOUT: "), end="")
  19. if p.stderr:
  20. print(textwrap.indent(p.stderr, "STDERR: "), end="")
  21. exit(p.returncode)
  22. if __name__ == "__main__":
  23. main()