Skip to content

Instantly share code, notes, and snippets.

@brando90
Last active February 27, 2019 04:49
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 brando90/99b10cdc73dc6b604ca661712c1c7b0d to your computer and use it in GitHub Desktop.
Save brando90/99b10cdc73dc6b604ca661712c1c7b0d to your computer and use it in GitHub Desktop.
import subprocess
def talk_to_python_interactively():
fw = open("tmpout", "wb")
fr = open("tmpout", "r")
p = subprocess.Popen(['python'],stdin=subprocess.PIPE,stdout=fw,stderr=fw,)
out = frw.readline()
print(out)
print(len(out))
print(type(out))
p.stdin.write( bytes('print(1)', 'utf-8') )
out = fr.read()
print(out) # prints nothing interesting
if __name__ == '__main__':
talk_to_python_interactively()
print('end of main')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment