Created
March 12, 2018 22:45
-
-
Save deeplook/cba960baef59817e0a512e46b4b73a0c to your computer and use it in GitHub Desktop.
Testing capturer to output ANSI escape sequences over subprocesses.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| """ | |
| Testing capturer to output ANSI escape sequences over subprocesses. | |
| """ | |
| import subprocess | |
| from capturer import CaptureOutput | |
| cmd0 = """echo '{"result":42}' > foo.json; pygmentize foo.json""" | |
| cmd1 = """pygmentize foo.json""" | |
| cmd2 = """echo foo.json | pygmentize""" | |
| for cmd in (cmd0, cmd1, cmd2): | |
| print('cmd') | |
| print(' ' + cmd) | |
| print('subprocess.getoutput(cmd)') | |
| print(' ' + subprocess.getoutput(cmd).strip()) | |
| print("subprocess.check_output(cmd.split()).decode('utf-8')") | |
| print(' ' + subprocess.check_output(cmd.split()).decode('utf-8').strip()) | |
| print('capturer, subprocess.call(cmd.split())') | |
| with CaptureOutput() as capturer: | |
| subprocess.call(cmd.split()) # also prints output | |
| for line in capturer.get_lines(): | |
| print(' ' + line) | |
| print('capturer, subprocess.check_output(cmd.split())') | |
| with CaptureOutput() as capturer: | |
| output = subprocess.check_output(cmd.split()) # also prints output | |
| print(output.decode('utf-8')) | |
| for line in capturer.get_lines(): | |
| print(' ' + line) | |
| print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment