On my windows system, I would like to use Runtime.getRuntime().exec(command) to launch a subprocess with a python script and have the command prompt terminal open so users can see the process working. My command is something like:
val command = "cmd /c python ~path_to_file~ ~args~"
I'm aware there's an alternate method to print the contents of the command prompt back into the original terminal via something like:
import java.util.Scanner
fun main(args: Array<String>) {
val proc = Runtime.getRuntime().exec("cmd /C dir")
Scanner(proc.inputStream).use {
while (it.hasNextLine()) println(it.nextLine())
}
}
Just wondering if there's another option I haven't seen yet.
I think you should use ProcessBuilder's redirecting:
fun main() {
ProcessBuilder("cmd", "/C", "dir")
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor()
}
This example has same behavior as yours.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With