Skip to content

Process

The @std/process module runs external commands and captures their output.

import process from "@std/process"
let result = process.run("echo", ["Hello"])
println(result.stdout)
println(result.stderr)
println(result.exit)

Runs a command with optional arguments.

Arguments:

NameTypeDefaultDescription
cmdstringnoneCommand to execute.
args[]any[]Command arguments.

Returns: a result struct.

Result fields:

NameTypeDescription
stdoutstringCaptured standard output.
stderrstringCaptured standard error.
exitintExit code.
import process from "@std/process"
let result = process.run("git", ["--version"])
if result.exit == 0 {
println(result.stdout)
} else {
println(result.stderr)
}

Use the exit field to check whether the command succeeded.

import process from "@std/process"
let result = process.run("nubo", ["--version"])
if result.exit != 0 {
println("Command failed:")
println(result.stderr)
}
fn printCommand(command: string, args: []string) void {
let result = process.run(command, args)
println(result.stdout)
}