Skip to content

Std\Process

Process – process management, environment, and command execution.

Provides environment variable access, command execution with output capture, and subprocess management with stdin/stdout pipes. Async functions (exec, execStatus, readAll, wait) block the current fiber without blocking the OS thread.

Get the value of an environment variable. Returns an empty string if not set.

import getenv from Std\Process in
getenv "HOME" # => "/home/user"

Returns the current working directory.

import getcwd from Std\Process in
getcwd # => "/home/user/project"

Terminate the process with the given exit code.

import exit from Std\Process in
exit 0

Execute a shell command and return its stdout as a string. Async.

import exec from Std\Process in
let output = exec "ls -la" in
println output

Execute a shell command and return its exit status code. Async.

import execStatus from Std\Process in
let code = execStatus "make build" in
println (show code)

Set an environment variable. Returns 0 on success.

import setenv from Std\Process in
setenv "MY_VAR" "hello"

Returns the system hostname.

import hostname from Std\Process in
hostname # => "myhost"

Spawn a subprocess without waiting for it to finish. Returns a process handle (Int).

import spawn, wait from Std\Process in
let proc = spawn "sleep 5" in
let status = wait proc in
println (show status)

Read a single line from the subprocess stdout.

import spawn, readLine from Std\Process in
let proc = spawn "echo hello" in
readLine proc # => "hello"

Read all remaining stdout from a subprocess as a string. Async.

Wait for a subprocess to exit and return its exit status. Async.

Send a signal to a subprocess. Returns 0 on success.

import spawn, kill from Std\Process in
let proc = spawn "sleep 100" in
kill proc 15 # SIGTERM

Write a string to the subprocess stdin. Returns the number of bytes written.

Close the stdin pipe of a subprocess. Returns 0 on success.

Returns the OS process ID of a subprocess.

import spawn, pid from Std\Process in
let proc = spawn "sleep 10" in
pid proc # => 12345