1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.io.BufferedReader import java.io.InputStreamReader fun main() { val command = "ls" // Comando a ejecutar (puedes cambiarlo) try { val process = ProcessBuilder(command.split("\\s".toRegex())) .redirectErrorStream(true) .start() val reader = BufferedReader(InputStreamReader(process.inputStream)) var line: String? while (reader.readLine().also { line = it } != null) { println(line) } process.waitFor() process.destroy() } catch (e: Exception) { e.printStackTrace() } } |