Skip to content

Repository files navigation

GitHub Actions Workflow StatusMaven Central VersionSonatype Nexus (Snapshots)

KProcess

Co-routine, DSL-friendly process launching from Kotlin.

Usage

  • Executing a process and capturing the results to a List<String>
val result = execToList { commandLine("git", "version") }
result.output.forEach { println(it) }
  • Executing a process and processing standard output as a Sequence<String>
val result = exec {
commandLine("git", "version")
consumeLineSequence { it.sumOf { it.length } }
}
  • Executing a process and writing standard output to a file
 execToFile(File("git.version")) { commandLine("git", "version") }
  • Executing a process and process the standard output stream
val result = exec {
commandLine("git", "version")
consumeStream { inputStream ->val file =File.createTempFile("git.", ".version")
GZIPOutputStream(file.outputStream()).use { inputStream.copyTo(it) }
file
}
}

Shell Session

For executing multiple commands in a single shell session, use the shellSession function:

shellSession {
mkdir("foo")
cd("foo")
exec("git", "init")
}

Key Features

  • Non-zero exit values are considered a failure by default (configure failOnNonZeroExit) and throw an exception;
  • Standard error is, by default, captured to a List<String>

Getting Started

Gradle:

Maven Central VersionSonatype Nexus (Snapshots)

dependencies {
implementation("io.cloudshiftdev.kprocess:kprocess:<version>")
}

About

Kotlin process launcher; coroutine-friendly, DSL-enabled.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages