Kotlin multiplatform library for launching child processes, monitoring their state, and capturing output. Built with kotlinx.coroutines and kotlinx.io.
val result = exec {
// some command line program
arg("curl")
args("-d", "@-")
arg("https://my.api")
// redirect streams
stdin = Redirect.Pipe
stdout = Redirect.Pipe
stderr = Redirect.Write("/log/file")
// pipe input data to stdin
input {
append("Hello, World")
}
// check for errors
check = true
}
// use result
println(result.output)Ksubprocess supports the following platforms:
- JVM via
java.lang.Process - Native/Linux via
fork/exec - Native/Windows via
CreateProcess - Native/macOS via
NSTask
repositories {
mavenCentral()
// Or snapshots
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
}
dependencies {
implementation("org.drewcarlson:ksubprocess:$VERSION")
}