Created
October 10, 2018 21:25
-
-
Save rwarren/38ca61f4bb106661342f97eaabf72ad0 to your computer and use it in GitHub Desktop.
fiddling with subprocess piping
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
import time | |
import sys | |
DELAY = 0.2 | |
for i in range(10): | |
sys.stdout.write("1") | |
time.sleep(DELAY) | |
sys.stdout.write("\r\n") | |
for i in range(10): | |
sys.stdout.write("2") | |
time.sleep(DELAY) | |
sys.stdout.write("\r") | |
for i in range(10): | |
sys.stdout.write("3") | |
time.sleep(DELAY) | |
sys.stdout.write("\n") | |
sys.stdout.write("done!\n") |
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
import subprocess | |
import select | |
import io | |
def main(): | |
args = ( | |
"python", | |
"-u", | |
"dumper.py", | |
) | |
proc = subprocess.Popen(args, | |
stdout=subprocess.PIPE, | |
#encoding="utf8", | |
#universal_newlines=True, | |
#bufsize = 0, | |
) | |
reader = io.TextIOWrapper(proc.stdout, | |
encoding='utf8', | |
) | |
print("starting") | |
for line in reader: | |
line=line.replace("\r", "\\r") | |
line=line.replace("\n", "\\n") | |
print("foo: " + line.strip()) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment