Process
Command Execution
import process
Running Commands
| Function | Signature | Description |
|---|
runCommand | (cmd: String) r: CommandResult | Execute shell command, capture output |
runProgram | (path: String) r: Int | Execute program, return exit code |
runProgramRequest | (path: String, requestContent: String) r: Int | Materialize private request content and execute an exact program path with one request-file argument, without a command shell |
execCommand | (cmd: String) r: CommandResult | Execute a shell command and return status/output |
runCommandOutput | (cmd: String) r: String | Execute and return stdout |
runCommandOrAbort | (cmd: String) r: Void | Execute, abort on failure |
CommandResult
| Function | Description |
|---|
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
| Function | Signature | Description |
|---|
processFork() | r: Int | Fork process (returns child PID in parent, 0 in child) |
waitPid(pid: Int, flags: Int) | r: Int | Wait for child (0=blocking, 1=WNOHANG) |
processExit(code: Int) | Void | Terminate process |
getPid() | r: Int | Get 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
| Function | Signature | Description |
|---|
get | (name: String) r: String | Get env var (empty if missing) |
has | (name: String) r: Bool | Check if env var exists |
set | (name: String, value: String) r: Bool | Set env var |
removeEnv | (name: String) r: Bool | Remove env var |
tryGet | (name: String) r: Option<String> | Get env var as Option |
getOrDefault | (name: String, default: String) r: String | Get 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
| Function | Description |
|---|
__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 |