sys module
Process-level information and control: identity (platform, version, arch, pid, hostname, user), command-line arguments, environment variables, working directory, and process termination.
import "sys" as sys;
print("bnl", sys.version, "on", sys.platform, sys.arch);
print("pid:", sys.pid());
print("user:", sys.username());
print("argv:", sys.argv());
print("cwd:", sys.cwd());
Constants
| Name | Description |
|---|---|
sys.platform | "windows", "linux", "darwin", … |
sys.version | bnl interpreter version string. |
sys.arch | CPU architecture: "x86_64", "arm64", "x86", "arm", or "unknown". |
Command-line arguments
| Function | Description |
|---|---|
sys.argc() → number | Count of args passed after the script path. |
sys.arg(i) → string | null | The i-th argument (0-indexed), or null if out of range. |
sys.argv() → list | All CLI args as a list of strings. |
Environment variables
| Function | Description |
|---|---|
sys.env(name) → string | null | Look up one environment variable. |
sys.setenv(name, value) → null | Set or overwrite an env var. Throws if name is empty or contains =. |
sys.unsetenv(name) → null | Remove an env var. No-op if it doesn't exist. |
sys.envs() → map | Snapshot of every environment variable as a {KEY: value} map. |
Process control
| Function | Description |
|---|---|
sys.exit(code) | Terminate with the given exit code. Runs atexit handlers. |
sys.abort() | Abnormal termination — no atexit handlers; dumps core on Unix. Use for "unrecoverable" cases where exit would be misleading. |
Process & host info
| Function | Description |
|---|---|
sys.pid() → number | Current process id. |
sys.cpu_count() → number | Number of logical CPUs, or 0 if unknown. |
sys.hostname() → string | Machine hostname. |
sys.username() → string | null | Current user name, or null if unknown. |
sys.home() → string | null | User home directory ($HOME on Unix, %USERPROFILE% on Windows), or null if unset. |
sys.executable() → string | Full path to the running bnl interpreter binary. |
sys.script() → string | null | Path of the entry .bnl script, or null for REPL / -e inline code. |
Paths
| Function | Description |
|---|---|
sys.cwd() → string | Current working directory. UTF-8 on every OS. |
sys.chdir(path) → null | Change the working directory. Throws if the path is invalid. |
sys.tempdir() → string | OS temp directory (%TEMP% / /tmp / $TMPDIR). |