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. This is a raw lookup: Windows CI and many desktop sessions have USERPROFILE but not HOME.

import getenv from Std\Process in
getenv "PATH" # non-empty when the process inherited a PATH

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 program directly and return its stdout as a string. The argument sequence excludes argv[0]. Async; no shell is invoked implicitly.

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

Execute a program directly 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

POSIX argv as a sequence of strings: program or script path, then user arguments. After yonac -o hello && ./hello a b, the first element is ./hello. After yona script.yona a b, the first element is the script path.

Absolute path of the running executable (/proc/self/exe on Linux).

The same version string as yonac --version.

Directory for temporary files (TMPDIR / TEMP / platform default).

Create a unique empty file from a prefix and suffix (mkstemp style). The prefix must not contain path separators.

Execute file with an argument sequence that excludes argv[0] (no shell). Inherit stdin, stdout, and stderr. Wait and return the exit status.

runWithArgv0 : String -> String -> [a] -> Int

Section titled “runWithArgv0 : String -> String -> [a] -> Int”

Execute file while setting the child-visible argv[0] explicitly. The final argument sequence still excludes argv[0]. This is intended for launchers such as yona, which execute a temporary binary but expose the script path, -, or -e as the program name.

Replace the current process with file and the given arguments, excluding argv[0] (Unix execve; Windows waits then exits).