dogma:process
import { stdout_writeln, env_get, args } from "dogma:process"
The host must grant the dogma:process capability for these functions to be available.
Stream types🔗
Stdout, Stderr, and Stdin are struct types. Obtain instances via stdout(), stderr(), stdin().
Output functions🔗
| Function | Signature | Description |
stdout_write | (msg: String) | Write to stdout without newline |
stdout_writeln | (msg: String) | Write to stdout with newline |
stderr_write | (msg: String) | Write to stderr without newline |
stderr_writeln | (msg: String) | Write to stderr with newline |
| Function | Signature | Description |
stdin_read_line | () -> String | Read one line from stdin (newline stripped) |
Environment🔗
| Function | Signature | Description |
env_get | (name: String) -> String | Get environment variable value (empty string if unset) |
env_set | (name: String, value: String) | Set environment variable |
args | () -> [String] | Get command-line arguments (args[0] is program name) |
exit | (code: i32) | Exit process with status code |
import { stdout_writeln, stderr_writeln, env_get, args, exit } from "dogma:process"
fn main() {
let arguments = args()
if arguments.len() < 2 {
stderr_writeln("Usage: program <name>")
exit(1)
}
let name = arguments[1]
let greeting = env_get("GREETING")
let msg = if greeting == "" { "Hello" } else { greeting }
stdout_writeln(f"{msg}, {name}!")
}