Skip to content

Instantly share code, notes, and snippets.

@vorobeij
Created August 19, 2022 20:55
Show Gist options
  • Save vorobeij/6a73784fb202dfd4c85120a51913ba50 to your computer and use it in GitHub Desktop.
Save vorobeij/6a73784fb202dfd4c85120a51913ba50 to your computer and use it in GitHub Desktop.
fun String.cmd(workingDir: File): String? {
try {
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()
} catch(e: IOException) {
e.printStackTrace()
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment