I am running a Python script that runs a Java class that requires nondeterministic user input:
import sys
import subprocess
from subprocess import Popen, PIPE
p = Popen("java myclass", shell=True, stdout=subprocess.PIPE)
while True:
inline = p.stdout.readline()
if not inline:
break
sys.stdout.write(inline)
sys.stdout.flush()
When output is displayed using System.out.print(), the output is displayed properly. However, when a prompt for user input is printed with System.out.print(), the output is not displayed. I tried switching p.stdout.readline() to p.stdout.read(), but then no output is displayed. Is there a way to display an input prompt that does not have a carriage return?
EDIT
For example, if the Java class contains the following:
System.out.println("Message 1);
System.out.println("Message 2);
System.out.print("Enter a number:")
Running the pure Java code would display all 3 lines.
The code running through Python would only display the following:
Message 1
Message 2
stripto remove the carriage return :inline = p.stdout.readline().strip()