Created
April 26, 2015 04:22
-
-
Save detly/7ac1a7c1f51e14fc670e to your computer and use it in GitHub Desktop.
This file contains 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 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