Skip to content

Instantly share code, notes, and snippets.

@detly
Created April 26, 2015 03:20
Show Gist options
  • Save detly/8bd36a22cbb668d8f225 to your computer and use it in GitHub Desktop.
Save detly/8bd36a22cbb668d8f225 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import asyncio
import sys
import pexpect
@asyncio.coroutine
def run():
cmd = ' '.join([
sys.executable,
'-c \'raise SystemExit("Blorp")\''
])
p = pexpect.spawn(cmd)
while True:
try:
_ = yield from p.expect_exact('\r', async=True)
print("1. before: {:s}".format(repr(p.before)))
except pexpect.EOF as e:
print("2. before: {:s}".format(repr(p.before)))
break
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