Skip to content

Instantly share code, notes, and snippets.

@rwarren
Created October 10, 2018 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rwarren/38ca61f4bb106661342f97eaabf72ad0 to your computer and use it in GitHub Desktop.
Save rwarren/38ca61f4bb106661342f97eaabf72ad0 to your computer and use it in GitHub Desktop.
fiddling with subprocess piping
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")
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