I am trying to accomplish a pseudo console with python's subprocess module for my web app. The point of the webapp is to be able to run and interact with python code via the web. I have a simple test.py script that has some sleeps and an input for testing purposes.
I am using process = subprocess.Popen(['python', "-u",'test.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
to run the file in a new subprocess.
I am retrieving the output lines like this:
for line in iter(process.stderr.readline, ''):
#line = line.rstrip('\n')
print(line)
sys.stdout.flush() # Flush the output buffer
Whenever my test.py python program gets to the input line, the print doesn't print the input line itself unless there is a newline character within the input prompt of test.py.
I was wondering if there is any way to get the output of the current line of the subprocess rather than only beeing able to access "processed" lines.
I also tried accessing stderr to no avail, I tried iterating over stdout.read until an empty char or a newline char was found, also to no avail.
Would love any help regarding this!