First of all a thank you to @Slaw. Indeed consuming the output logs fixed the error. You may Note I switched to using a ProcessBuilder
. I tried that before but without consuming the output that didn't work. The new Kotlin code is the following:
class ScriptExecutor {
companion object{
@JvmStatic
fun execute(s: String){
val process = ProcessBuilder("/bin/sh", s).start()
// Stream output and error logs
val output = BufferedReader(InputStreamReader(process.inputStream))
val error = BufferedReader(InputStreamReader(process.errorStream))
// Print output in the background (optional)
Thread {
output.lines().forEach { println(it) }
}.start()
Thread {
error.lines().forEach { println(it) }
}.start()
}
}}
The outputs get printed to the console and the consuming is outsourced to another thread.