Im launching a simple python script and trying to ...
# announcements
e
Im launching a simple python script and trying to read its output like this
Copy code
val 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:
Copy code
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?
s
won’t it just block on waiting for the python process to return
e
it actually runs on some other thread created by
ExecutorService
I've also tried
print("ABC", flush=True)
no luck.
It works now with the
readLine