Skip to content

Instantly share code, notes, and snippets.

@detly
Created April 26, 2015 04:22
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 detly/7ac1a7c1f51e14fc670e to your computer and use it in GitHub Desktop.
Save detly/7ac1a7c1f51e14fc670e to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import asyncio
import sys
import pexpect
@asyncio.coroutine
def run():
p = pexpect.spawn('./weirdness')
while True:
try:
_ = yield from p.expect_exact('\r', async=True)
except pexpect.EOF as e:
print("2. output: {:s}".format(repr(p.before)))
return
else:
full_data = p.before
try:
full_data += p.after
except TypeError:
# p.after is an EOF exception
pass
print("1. output: {:s}".format(repr(full_data)))
def main():
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
loop.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment