Last active
February 27, 2019 04:49
-
-
Save brando90/99b10cdc73dc6b604ca661712c1c7b0d 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
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