ProcessNote: Use processFork() instead of fork() to avoid shadowing POSIX fork().

Process

Command Execution

import process

Running Commands

FunctionSignatureDescription
runCommand(cmd: String) r: CommandResultExecute shell command, capture output
runProgram(path: String) r: IntExecute program, return exit code
runProgramRequest(path: String, requestContent: String) r: IntMaterialize private request content and execute an exact program path with one request-file argument, without a command shell
execCommand(cmd: String) r: CommandResultExecute a shell command and return status/output
runCommandOutput(cmd: String) r: StringExecute and return stdout
runCommandOrAbort(cmd: String) r: VoidExecute, abort on failure

CommandResult

FunctionDescription
commandWasSuccessful(result)Check if command succeeded
commandOutput(result)Get stdout output
isSuccess(result)Check exit code == 0

Example

let result = runCommand("ls -la")
if commandWasSuccessful(result) {
    println(commandOutput(result))
}

let exitCode = runProgram("/usr/bin/gcc")

// Suitable for a structured request protocol: the helper path is not
// shell-expanded and the runtime creates and removes the private request file.
let helperStatus = runProgramRequest("/usr/lib/seen/seen-pkg", requestContent)

Process Management

FunctionSignatureDescription
processFork()r: IntFork process (returns child PID in parent, 0 in child)
waitPid(pid: Int, flags: Int)r: IntWait for child (0=blocking, 1=WNOHANG)
processExit(code: Int)VoidTerminate process
getPid()r: IntGet current process ID

Note: Use processFork() instead of fork() to avoid shadowing POSIX fork().

Example

let pid = processFork()
if pid == 0 {
    // child process
    println("I'm the child")
    processExit(0)
} else {
    // parent process
    println("Child PID: {pid}")
    waitPid(pid, 0)
}

Environment Variables

import env
FunctionSignatureDescription
get(name: String) r: StringGet env var (empty if missing)
has(name: String) r: BoolCheck if env var exists
set(name: String, value: String) r: BoolSet env var
removeEnv(name: String) r: BoolRemove env var
tryGet(name: String) r: Option<String>Get env var as Option
getOrDefault(name: String, default: String) r: StringGet with fallback

Example

let home = get("HOME")
println("Home: {home}")

if has("DEBUG") {
    println("Debug mode enabled")
}

set("MY_VAR", "hello")

Command-Line Arguments

let arguments = args()  // returns Array<String>
for arg in arguments {
    println(arg)
}

Shell Quoting

let safe = shellQuote("file with spaces.txt")
// Returns: 'file with spaces.txt'

Runtime Functions

FunctionDescription
__ExecuteProgram(path)Execute program, return exit code
__ExecuteProgramRequest(path, requestPath)Internal exact-argument primitive used by the structured request bridge
__seen_fork()Fork process
__seen_waitpid(pid, flags)Wait for child
__seen_exit(code)Exit process
__seen_getpid()Get PID
__HasEnv(name)Check env var
__GetEnv(name)Get env var
__SetEnv(name, value)Set env var
__RemoveEnv(name)Remove env var
seen_runtime_init(argc, argv)Initialize runtime with args
Architected in Kotlin. Rendered with Materia. Powered by Aether.
© 2026 Yousef.