Vlad's Roam Garden

Powered by 🌱Roam Garden
  import java.util.concurrent.TimeUnit
  import java.io.File

operator fun String.invoke(workingDir: File = File(".")): String {
    val parts = this.split("\\s".toRegex())
    val proc = ProcessBuilder(*parts.toTypedArray())
            .directory(workingDir)
            .redirectOutput(ProcessBuilder.Redirect.PIPE)
            .redirectError(ProcessBuilder.Redirect.PIPE)
            .start()

    proc.waitFor(60, TimeUnit.MINUTES)
    return proc.inputStream.bufferedReader().readText()
}

val String.e get()= invoke()

// example
"ls".e