Process

The Process module provides functions for running commands, controlling process execution, and accessing process information.

Command Execution

Process.run
String -> Result () String
Runs a shell command. Returns Ok () on success or Err with error message on failure.
match Process.run "ls -la"
  | Ok _ -> println "Command succeeded"
  | Err msg -> println "Error: ${msg}"
Process.run-capture
String -> Result String String
Runs a shell command and captures its output. Returns Ok output on success.
match Process.run-capture "pwd"
  | Ok output -> println "Current dir: ${output}"
  | Err msg -> println "Error: ${msg}"
Process.run-args
String -> List String -> Result String String
Runs a command with a list of arguments. Safer than shell string interpolation.
match Process.run-args "git" ["status", "--short"]
  | Ok output -> println output
  | Err msg -> println "Error: ${msg}"

Process Information

Process.pid
() -> Int
Returns the current process ID.
println "PID: ${Process.pid()}"
# => "PID: 12345"
Process.ppid
() -> Int
Returns the parent process ID.
println "Parent PID: ${Process.ppid()}"
# => "Parent PID: 12344"
Process.arch
() -> String
Returns the system architecture (e.g., "x86_64", "aarch64").
println "Architecture: ${Process.arch()}"
# => "Architecture: aarch64"
Process.environ
() -> Map String String
Returns all environment variables as a map.
env = Process.environ()
match Map.get "PATH" env
  | Some path -> println "PATH: ${path}"
  | None -> println "PATH not set"

Process Control

Process.sleep
Int -> ()
Pauses execution for the specified number of milliseconds.
# Sleep for 500 milliseconds
Process.sleep 500
println "Done waiting!"
Process.sleep-seconds
Int -> ()
Pauses execution for the specified number of seconds.
# Sleep for 2 seconds
Process.sleep-seconds 2
println "Done waiting!"
Process.exit
Int -> a
Exits the process with the specified exit code. Does not return.
if error-occurred then
  println "Fatal error!"
  Process.exit 1
else
  println "Success"
  Process.exit 0