All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jvmMain.com.zegreatrob.tools.adapter.git.RunProcess.jvm.kt Maven / Gradle / Ivy

There is a newer version: 1.5.10
Show newest version
package com.zegreatrob.tools.adapter.git

import java.io.File
import java.nio.charset.Charset

actual fun runProcess(args: List, workingDirectory: String, env: Map): String {
    val process = ProcessBuilder(args)
        .also { it.environment().putAll(env) }
        .directory(File(workingDirectory))
        .start()
    val outputText = process.inputStream.readAllBytes().toString(Charset.defaultCharset())
    val error = process.errorStream.readAllBytes().toString(Charset.defaultCharset())
    process.waitFor()
    if (process.exitValue() != 0) {
        throw Error("$outputText\n$error")
    }
    return outputText
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy