Skip to content

Instantly share code, notes, and snippets.

@moriyoshi
Created January 30, 2013 09:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moriyoshi/4671896 to your computer and use it in GitHub Desktop.
Save moriyoshi/4671896 to your computer and use it in GitHub Desktop.
import os
import pty
pair = pty.fork()
if not pair[0]:
os.execvp('python', ['python'])
s = os.fdopen(pair[1], 'w+')
while True:
c = s.read(1)
if c == '>':
c = s.read(1)
if c == '>':
c = s.read(1)
if c == '>':
break
s.write('1 + 1\r\n')
assert s.readline().strip() == '1 + 1'
print s.readline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment