Skip to content

process

import process
FunctionSignatureDescription
exec(String, List[String]) -> Result[String, String]Execute a command and return its stdout as a string
exit(Int) -> UnitExit the process with the given status code
stdin_lines() -> Result[List[String], String]Read all lines from standard input
exec_in(String, String, List[String]) -> Result[String, String]Execute a command in a specific working directory
exec_with_stdin(String, List[String], String) -> Result[String, String]Execute a command with input piped to its stdin
exec_status(String, List[String]) -> Result[{code: Int, stdout: String, stderr: String}, String]Execute a command and return exit code, stdout, and stderr

process.exec(cmd: String, args: List[String]) -> Result[String, String]

Section titled “process.exec(cmd: String, args: List[String]) -> Result[String, String]”

Execute a command and return its stdout as a string

let output = process.exec("ls", ["-la"])

Exit the process with the given status code

process.exit(1)

process.stdin_lines() -> Result[List[String], String]

Section titled “process.stdin_lines() -> Result[List[String], String]”

Read all lines from standard input

let lines = process.stdin_lines()

process.exec_in(dir: String, cmd: String, args: List[String]) -> Result[String, String]

Section titled “process.exec_in(dir: String, cmd: String, args: List[String]) -> Result[String, String]”

Execute a command in a specific working directory

let output = process.exec_in("/tmp", "pwd", [])

process.exec_with_stdin(cmd: String, args: List[String], input: String) -> Result[String, String]

Section titled “process.exec_with_stdin(cmd: String, args: List[String], input: String) -> Result[String, String]”

Execute a command with input piped to its stdin

let output = process.exec_with_stdin("cat", [], "hello")

process.exec_status(cmd: String, args: List[String]) -> Result[{code: Int, stdout: String, stderr: String}, String]

Section titled “process.exec_status(cmd: String, args: List[String]) -> Result[{code: Int, stdout: String, stderr: String}, String]”

Execute a command and return exit code, stdout, and stderr

let r = process.exec_status("ls", []) // {code, stdout, stderr}

process.env(key: String) -> Option[String]

Section titled “process.env(key: String) -> Option[String]”

Get the value of an environment variable, or None if not set.

let home = process.env("HOME") ?? "/tmp"

Get command-line arguments as a list of strings.

let args = process.args()

Get the current process ID.

let my_pid = process.pid()

process.spawn(cmd: String, args: List[String]) -> Result[Int, String]

Section titled “process.spawn(cmd: String, args: List[String]) -> Result[Int, String]”

Spawn a child process without waiting, return its PID.

let pid = process.spawn("node", ["server.js"])

process.kill(pid: Int, signal: Int) -> Result[Unit, String]

Section titled “process.kill(pid: Int, signal: Int) -> Result[Unit, String]”

Send a signal to a process by PID (e.g. 15 for SIGTERM, 9 for SIGKILL).

process.kill(pid, 15)

Check if a process with the given PID is still running.

let running = process.is_alive(pid)