ec
02/29/2020, 9:24 PMval pp = Path.of(System.getProperty("user.dir"),"test.py")
val p = ProcessBuilder("python3", pp.toString())
p.redirectErrorStream(true)
val pr = p.start()
pr.outputStream.close()
while (true) {
if (pr.inputStream.available() < 1)
Thread.sleep(10)
else {
val content = pr.inputStream.bufferedReader().use(BufferedReader::readText)
println(content)
}
}
Python script:
import time
print("ABC")
i = 0
while True:
print("ABC")
i += 1
time.sleep(1)
But nothing gets printed to screen. (Unless I remove the while
part, then it actually prints "ABC" so python path, script path is correct) What is the correct way to do this?Shawn
02/29/2020, 9:32 PMec
02/29/2020, 9:38 PMExecutorService
ec
02/29/2020, 9:39 PMprint("ABC", flush=True)
no luck.ec
02/29/2020, 9:43 PMreadLine