79281207

Date: 2024-12-14 19:05:41
Score: 2
Natty:
Report link

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.

Reasons:
  • Blacklisted phrase (0.5): thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Slaw
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Chicovara