Builder

class Builder(val command: String) : Blocking.Builder(source)

Creates a new Process.

e.g. (Shell commands on a Unix system)

val out = Process.Builder("sh")
    .args("-c")
    .args("sleep 1; exit 5")
    .destroySignal(Signal.SIGKILL)
    .stdin(Stdio.Null)
    // Synchronous API (All platforms)
    .createOutput { timeoutMillis = 1_500 }

assertEquals(5, out.processInfo.exitCode)

e.g. (Executable file)

val b = Process.Builder(myExecutableFile)
    .args("--some-flag")
    .args("someValue")
    .args("--another-flag", "anotherValue")
    .environment {
        remove("HOME")
        // ...
    }
    .stdin(Stdio.Null)
    .stdout(Stdio.File.of("logs/myExecutable.log", append = true))
    .stderr(Stdio.File.of("logs/myExecutable.err"))

// Synchronous API (Jvm/Native)
b.createProcess().use { p ->
    // ...
}

// Asynchronous API (All platforms)
myScope.launch {
    b.createProcessAsync().use { p ->
        // ...
    }
}

Constructors

Link copied to clipboard
constructor(command: String)
constructor(executable: File)

An alternate constructor for an executable File. Will take the absolute & normalized path to use for command.

Properties

Link copied to clipboard
@JvmField
val command: String

The command to run, such as a program on PATH, or a file path (relative or absolute) to a program.

Functions

Link copied to clipboard
fun args(arg: String): Process.Builder

Add a single argument.

fun args(vararg args: String): Process.Builder
fun args(args: List<String>): Process.Builder

Add multiple arguments.

Link copied to clipboard
fun async(context: CoroutineContext?): Process.Builder

DEFAULT: Dispatchers.IO (Jvm/Native), Dispatchers.Default (Js/WasmJs)

Link copied to clipboard

Changes the working directory of the spawned process.

Link copied to clipboard
inline fun createOutput(block: Output.Options.Builder.() -> Unit): Output

Blocks the current thread until Process completion, Output.Options.Builder.timeoutMillis is exceeded, or Output.Options.Builder.maxBuffer is exceeded.

Link copied to clipboard
suspend fun createOutputAsync(): Output
inline suspend fun createOutputAsync(block: Output.Options.Builder.() -> Unit): Output

Creates the Process asynchronously using the configured async context and suspends until its completion, Output.Options.Builder.timeoutMillis is exceeded, or Output.Options.Builder.maxBuffer is exceeded.

Link copied to clipboard

Create the Process asynchronously using the configured async context.

Link copied to clipboard
Link copied to clipboard

DEFAULT: false

Link copied to clipboard
fun environment(block: MutableMap<String, String>.() -> Unit): Process.Builder

Configure the process' environment via lambda

fun environment(key: String, value: String): Process.Builder

Configure/overwrite an environment variable

Link copied to clipboard
Link copied to clipboard
fun Process.Builder.shell(enable: Boolean): Process.Builder

DEFAULT: false

Link copied to clipboard
fun stderr(destination: Stdio): Process.Builder

DEFAULT: Stdio.Pipe

Link copied to clipboard

DEFAULT: Stdio.Pipe

Link copied to clipboard
fun stdout(destination: Stdio): Process.Builder

DEFAULT: Stdio.Pipe

Link copied to clipboard

DEFAULT: true

Link copied to clipboard

DEFAULT: true

Link copied to clipboard

DEFAULT: false