Skip to content

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

License

Notifications You must be signed in to change notification settings

cloudshiftinc/kprocess

Repository files navigation

GitHub Actions Workflow Status Maven Central Version Sonatype 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 Version Sonatype Nexus (Snapshots)

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages