March Docs

Process

Process module: OS process interaction.

run/2 runs a command and waits for it to finish, returning the exit code and captured stdout. run_stream/2 returns a Seq(String) of output lines for pipeline-style processing without buffering the whole output.

env/1 and set_env/2 read and write OS environment variables. cwd/0, argv/0, pid/0 expose the current process context. exit/1 terminates the VM with the given exit code.

Types

typeProcessResultProcessResult = ProcessResult(Int, String, String)#
typeLiveProcessLiveProcess = LiveProcess(Int, Int)#

Functions

fnrunrun(command, args)#

Run command with args, wait for it to finish. Returns Ok(ProcessResult) or Err(msg).

fnrun_streamrun_stream(command, args)#

Run command and return its stdout as a Seq(String) of lines. Returns Ok(Seq) or Err(msg).

fnenvenv(name)#

Get the value of an environment variable. Returns Some(value) or None.

fnset_envset_env(name, value)#

Set an environment variable.

fncwdcwd()#

Returns the current working directory.

fnexitexit(code)#

Terminate the process with the given exit code.

fnargvargv()#

Returns the command-line arguments as List(String) (argv[0] is the executable).

fnpidpid()#

Returns the OS-level PID of the current process.

fnspawn_asyncspawn_async(command, args)#

Spawn a command asynchronously (non-blocking). Returns Ok(LiveProcess) immediately — the child process starts running in the background. Use read_line to consume its stdout, kill to terminate it, and wait_proc to reap its exit code.

fnread_lineread_line(p)#

Read one line from the live process's stdout. Returns Some(line) for each output line, or None when the process has closed its stdout (typically on exit). Blocks until a full line is available.

fnkillkill(p)#

Send SIGTERM to the live process.

fnwait_procwait_proc(p)#

Wait for the live process to exit and return its exit code. Also closes the stdout channel. Should be called after the process exits (read_line returned None) or after kill.

fnexit_codeexit_code(r)#

Extract the exit code from a ProcessResult.

fnstdoutstdout(r)#

Extract captured stdout from a ProcessResult.

fnstderrstderr(r)#

Extract captured stderr from a ProcessResult.

fnokok(r)#

True if the command exited with code 0.