Tanguv0.35.0
System & I/O19 exports
Raw Markdown

/process

Subprocess execution (run, spawn), environment variables (env, env-vars), working directory, and exit statuses.

(use /process)

Functions & symbols#

args#

function
(process/args) -> Array

Returns the array of command-line arguments passed to the running script.

Returns:Any
(let [file target] (process/args))

env#

function
(process/env) -> Map

Reads environment variables. With 0 args returns a Map of all vars; with 1 arg returns the value or (); with 2 args returns fallback when unset.

ParameterTypeOptionalDescription
nameStringrequiredEnvironment variable name
defaultAnyrequiredFallback value if variable is unset
Returns:Any
(let vars (process/env))
(let port (process/env "PORT" "8080"))

env-vars#

function
(process/env-vars) -> Map

Returns all environment variables inherited by the current process as a `Map`.

Returns:Any
(let env (process/env-vars))

err-port#

function
process/err-port -> Writer

Host standard error stream handle implementing `Write`, `Write-Text`, and `Flush`.

Returns:Any
(use {err-port} /process)
(write-line err-port "error!")

exec#

function
(process/exec cmd) -> String

Executes a shell command and captures its standard output as a String.

ParameterTypeOptionalDescription
cmdStringrequiredShell command string to execute
Returns:Any
(let out (process/exec "git rev-parse HEAD"))

exit#

function
(process/exit code) -> Never

Terminates the process with exit `code` (deprecated alias; prefer `process/exit-process`).

ParameterTypeOptionalDescription
codeIntrequiredProcess exit status code (0 for success)
Returns:Any

exit!#

function
(process/exit! [code]) -> Never

Immediately terminates the current process with the given integer exit code (defaults to 0).

ParameterTypeOptionalDescription
codeIntrequiredExit status code (0 for success, 1+ for failure)
Returns:Any
(process/exit! 1)

expect-env-var#

function
(expect-env-var name)

Returns the value of the environment variable `name`, or panics if undefined.

ParameterTypeOptionalDescription
nameAnyrequired—
Returns:Any

get-args#

function
(process/get-args) -> (Array String)

Returns CLI command-line arguments passed to the current program.

Returns:Any
(let args (process/get-args))

get-env#

function
(process/get-env name) -> (Or String None)

Looks up an environment variable by name, returning `()` if unset.

ParameterTypeOptionalDescription
nameString | KeySymbolrequiredEnvironment variable name
Returns:Any
(process/get-env "HOME")

has-env?#

function
(process/has-env? name) -> Bool

Returns true if the environment variable is set in the current process.

ParameterTypeOptionalDescription
nameStringrequiredEnvironment variable name
Returns:Any
(if (process/has-env? "DEBUG") (writeln "debugging enabled"))

in-port#

function
process/in-port -> Reader

Host standard input stream handle implementing `Read` and `Read-Text`.

Returns:Any
(use {in-port} /process)
(let line (read-line in-port))

out-port#

function
process/out-port -> Writer

Host standard output stream handle implementing `Write`, `Write-Text`, and `Flush`.

Returns:Any
(use {out-port} /process)
(write-line out-port "hello")

pid#

function
(process/pid) -> Int

Returns the current process identifier (PID).

Returns:Any
(let current-pid (process/pid))

run#

function
(process/run cmd) -> Map

Executes a subprocess directly without invoking `sh -c`, preventing shell command injection and returning `{:code Int :out String :err String :ok? Bool}`.

ParameterTypeOptionalDescription
cmd(Array String) | StringrequiredExecutable and argument array executed directly without a shell
optionsMaprequiredOptional execution options (`:cwd`, `:env`, `:clear-env`, `:in`)
Returns:Any
(let res (process/run ["git" "status" "--porcelain"]))
(let res (process/run ["env"] {:clear-env true :env {:MODE "safe"}}))

set-env#

function
(process/set-env name value) -> ()

Sets an environment variable for the current process.

ParameterTypeOptionalDescription
nameStringrequiredEnvironment variable name
valueStringrequiredEnvironment variable value
Returns:Any
(process/set-env "API_KEY" "secret")

set-env-var#

function
(process/set-env-var name value) -> None

Sets an environment variable for the current process and spawned children.

ParameterTypeOptionalDescription
nameString | KeySymbolrequiredVariable name
valueStringrequiredValue to set
Returns:Any
(process/set-env-var "LOG_LEVEL" "debug")

shell#

function
(process/shell cmd) -> Int

Executes a shell command streaming standard I/O to the console, returning the exit status code.

ParameterTypeOptionalDescription
cmdStringrequiredShell command string to execute
Returns:Any
(let code (process/shell "npm test"))

unset-env#

function
(process/unset-env name) -> ()

Unsets an environment variable from the current process.

ParameterTypeOptionalDescription
nameStringrequiredEnvironment variable name
Returns:Any
(process/unset-env "API_KEY")