# Module /process

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

```tangu
(use /process)
```

## Functions & symbols

### args

`(process/args) -> Array`

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

```tangu
(let [file target] (process/args))
```

### env

`(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.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `name` | `String` | no | Environment variable name |
| `default` | `Any` | no | Fallback value if variable is unset |

```tangu
(let vars (process/env))
(let port (process/env "PORT" "8080"))
```

### env-vars

`(process/env-vars) -> Map`

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

```tangu
(let env (process/env-vars))
```

### err-port

`process/err-port -> Writer`

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

```tangu
(use {err-port} /process)
(write-line err-port "error!")
```

### exec

`(process/exec cmd) -> String`

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

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `cmd` | `String` | no | Shell command string to execute |

```tangu
(let out (process/exec "git rev-parse HEAD"))
```

### exit

`(process/exit code) -> Never`

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

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `code` | `Int` | no | Process exit status code (0 for success) |

### exit!

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

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

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `code` | `Int` | no | Exit status code (0 for success, 1+ for failure) |

```tangu
(process/exit! 1)
```

### expect-env-var

`(expect-env-var name)`

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

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `name` | `Any` | no | — |

### get-args

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

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

```tangu
(let args (process/get-args))
```

### get-env

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

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

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `name` | `String | KeySymbol` | no | Environment variable name |

```tangu
(process/get-env "HOME")
```

### has-env?

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

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

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `name` | `String` | no | Environment variable name |

```tangu
(if (process/has-env? "DEBUG") (writeln "debugging enabled"))
```

### in-port

`process/in-port -> Reader`

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

```tangu
(use {in-port} /process)
(let line (read-line in-port))
```

### out-port

`process/out-port -> Writer`

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

```tangu
(use {out-port} /process)
(write-line out-port "hello")
```

### pid

`(process/pid) -> Int`

Returns the current process identifier (PID).

```tangu
(let current-pid (process/pid))
```

### run

`(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}`.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `cmd` | `(Array String) | String` | no | Executable and argument array executed directly without a shell |
| `options` | `Map` | no | Optional execution options (`:cwd`, `:env`, `:clear-env`, `:in`) |

```tangu
(let res (process/run ["git" "status" "--porcelain"]))
(let res (process/run ["env"] {:clear-env true :env {:MODE "safe"}}))
```

### set-env

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

Sets an environment variable for the current process.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `name` | `String` | no | Environment variable name |
| `value` | `String` | no | Environment variable value |

```tangu
(process/set-env "API_KEY" "secret")
```

### set-env-var

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

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

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `name` | `String | KeySymbol` | no | Variable name |
| `value` | `String` | no | Value to set |

```tangu
(process/set-env-var "LOG_LEVEL" "debug")
```

### shell

`(process/shell cmd) -> Int`

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

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `cmd` | `String` | no | Shell command string to execute |

```tangu
(let code (process/shell "npm test"))
```

### unset-env

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

Unsets an environment variable from the current process.

| Parameter | Type | Optional | Description |
| :--- | :--- | :--- | :--- |
| `name` | `String` | no | Environment variable name |

```tangu
(process/unset-env "API_KEY")
```
