Skip to content

Latest commit

 

History

History
69 lines (54 loc) · 2.33 KB

README.md

File metadata and controls

69 lines (54 loc) · 2.33 KB

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>")
}