terminalOS Integration

Execute OS processes, read environment variables, inspect files, and interact with the underlying system from BoxLang.

BoxLang provides two layers of OS interaction. The built-in layer covers process execution, environment variables, system properties, file metadata, timing, and console output — all available with no dependencies. The extended layer adds deep hardware and OS introspection via the optional bx-oshi module, and direct Java interop unlocks the full power of ProcessBuilder for advanced process pipelines.

📋 Table of Contents


🖥️ The server Scope — OS Quick Reference

The server scope is automatically populated at runtime with read-only OS and runtime metadata. The keys below are unmodifiable once the scope is initialized.

server.os

Operating system details sourced from Java system properties and the network stack.

Key
Example
Description

name

"Mac OS X"

OS name

version

"14.5"

OS version

arch

"aarch64"

CPU architecture

archModel

"aarch64"

Same as arch

hostname

"myserver.local"

Local hostname

ipAddress

"192.168.1.10"

Local IP address

macAddress

"a1:b2:c3:d4:e5:f6"

Primary MAC address

server.separator

Path and line separator characters for the current OS — useful for portable file path construction.

Key
Unix
Windows
Description

file

/

\

File path separator

path

:

;

Path list separator (like $PATH)

line

\n

\r\n

Line ending character(s)

server.java

JVM runtime information.

Key
Description

version

Java version string

vendor

JVM vendor name

archModel

CPU architecture

executionPath

Working directory at JVM startup

freeMemory

Current free JVM heap (bytes)

totalMemory

Total JVM heap allocated (bytes)

maxMemory

Maximum JVM heap allowed (bytes)

defaultLocale

Default locale display name

availableLocales

Sorted list of all available locales

pid

Current process ID

server.cli

CLI invocation details. args and parsed are only populated when running in CLI mode; they are empty string/struct in web/lambda contexts.

Key
Description

executionPath

Directory from which BoxLang was invoked

command

Full command line string (sun.java.command)

args

Array of raw CLI arguments (CLI mode only)

parsed

Struct of parsed flags and values (CLI mode only)

server.system

All Java system properties and OS environment variables. Disabled by default for security — enable in boxlang.json:

When enabled:

circle-exclamation

server.boxlang

BoxLang runtime metadata.

Key
Description

version

BoxLang version string

buildDate

Build date

codename

Release codename

boxlangId

Runtime instance hash

compiler

Compiler mode (asm, java, etc.)

cliMode

true when running as CLI

debugMode

true when debug mode is active

jarMode

true when running from a JAR

runtimeHome

Path to the BoxLang home directory

modules

Struct of loaded modules


⚙️ Process Execution

systemExecute() BIF

Execute any system process and capture its output.

Arguments:

Argument
Type
Required
Default
Description

name

string

Binary name or full path

arguments

string | array

null

Arguments — string is auto-tokenized (quotes preserved); array is used directly

timeout

long

unlimited

Max seconds to wait

terminateOnTimeout

boolean

false

Kill process when timeout is reached

directory

string

null

Working directory for the process

output

string

null

File path to redirect stdout to

error

string

null

File path to redirect stderr to

inheritEnvironment

boolean

true

Inherit parent process environment

environment

struct

{}

Additional/override environment variables (merged after inherit decision)

Return struct:

Key
Type
Description

output

string

Captured stdout (null if redirected to file)

error

string

Captured stderr (null if redirected to file)

exitCode

integer

Process exit code

pid

long

Process ID

timeout

boolean

Whether timeout was reached

terminated

boolean

Whether process was force-killed

Examples:

circle-info

For string arguments, BoxLang tokenizes using a regex that preserves quoted strings, so arguments="--format 'Hello World'" correctly passes two tokens. For guaranteed correctness, use an array.

bx:execute Component

The component version of systemExecute(). Results are distributed into separate named variables rather than returned as a struct.

Attributes:

Attribute
Type
Required
Default
Description

name

string

Binary name or full path

arguments

string | array

Process arguments

variable

string

Variable to receive stdout

errorVariable

string

Variable to receive stderr

exitCode

string

Variable to receive exit code

outputFile

string

File path to redirect stdout to

errorFile

string

File path to redirect stderr to

timeout

long

unlimited

Max seconds to wait

terminateOnTimeout

boolean

false

Kill process on timeout

directory

string

Working directory

inheritEnvironment

boolean

true

Inherit parent environment

environment

struct

{}

Additional environment variables

circle-info

Note that the component uses outputFile/errorFile (not output/error like the BIF).

Cross-Platform Shell Invocation

When you need shell features like pipes, redirects, or glob expansion:


🌍 Environment Variables & System Properties

getSystemSetting( key [, defaultValue] )

Retrieve a Java system property or OS environment variable by name.

Lookup order:

  1. Registered system setting providers (by namespace)

  2. Java system properties (System.getProperties())

  3. OS environment variables (System.getenv())

  4. defaultValue — or throws BoxRuntimeException if none provided

Notes:

  • Key names are case-sensitive

  • Namespace support via . separator (e.g., custom provider registered under myapp)

circle-check

.env File Auto-Loading (CLI)

When running in CLI mode, BoxLang automatically loads environment variables from .env files before your script executes. Two files are loaded in order — user-level first, then project-level:

File
Description

~/.box.env

User-level defaults — loaded on every CLI invocation (since BoxLang 1.13.0)

.env

Project-level file in the current working directory — values override user-level

All values are available immediately via getSystemSetting():

circle-info

The MiniServer has its own .env loading from the webroot — see the MiniServer documentation for details. For CLI .env behavior, see CLI Scripting.


📺 Console Output

BIF
Signature
Description

print()

print( message )

Write to stdout without a newline

println()

println( message )

Write to stdout with a trailing newline

systemOutput()

systemOutput( obj, addNewLine, doErrorStream )

Full control — stdout or stderr


⏱️ Timing & Performance

getTickCount( [unit] )

Returns a high-resolution system timer value. Default unit is "milli".

Unit
Returns

"milli" (default)

System.currentTimeMillis() — wall-clock milliseconds

"nano"

System.nanoTime() — monotonic nanoseconds

"second"

Current time in seconds

sleep( duration )

Pauses the current thread for duration milliseconds. Throws BoxRuntimeException if the thread is interrupted.


ℹ️ System & Runtime Information

getBoxVersionInfo()

Returns a struct with BoxLang runtime version details.

Key
Description

version

Version string (e.g., "1.13.0")

buildDate

Build date

codename

Release codename

boxlangId

Runtime instance identifier


📄 File & Disk Information

fileInfo( file ) / getFileInfo( file )

Both BIFs inspect a file or directory path. getFileInfo() is the verbose alias with additional OS-level attributes.

fileInfo() returns:

Key
Type
Description

name

string

Filename only

path

string

Absolute path

size

long

Size in bytes (0 for directories)

type

string

"file" or "directory"

lastModified

string

Formatted last-modified datetime

attributes

string

Empty string (compatibility key)

mode

string

Octal POSIX permissions (e.g., "644") — empty on Windows

read

boolean

Is the path readable

write

boolean

Is the path writable

execute

boolean

Is the path executable

checksum

string

MD5 checksum of file content (empty for directories)

getFileInfo() returns (different key set):

Key
Type
Description

name, path, size, type, lastModified

Same as above

parent

string

Parent directory absolute path

isHidden

boolean

Hidden file/directory

canRead / canWrite / canExecute

boolean

Permission flags

isArchive / isSystem

boolean

Windows DOS attributes only

isAttributesSupported

boolean

true on Windows

isModeSupported

boolean

true on POSIX systems

isCaseSensitive

boolean

Heuristic: is the FS case-sensitive

For file size details on disk partitions, use the bx-oshi module's getFreeSpace() / getTotalSpace() convenience BIFs.


📁 Temp Files & Directories


🔬 Deep OS Introspection — bx-oshi

The bx-oshi module wraps the OSHI libraryarrow-up-right to expose hardware and OS metrics with no native library requirements.

Convenience BIFs

BIF
Description

getCpuUsage( [interval] )

CPU utilization percentage

getFreeSpace( path )

Free disk space for the given path (bytes)

getTotalSpace( path )

Total disk capacity for the given path (bytes)

getSystemFreeMemory()

Free OS physical memory (bytes)

getSystemTotalMemory()

Total OS physical memory (bytes)

getJVMFreeMemory()

Free JVM heap (bytes)

getJVMTotalMemory()

Total JVM heap allocated (bytes)

Full Hardware & OS Access

For deeper data — CPU topology, network interfaces, disk I/O, sensors, batteries — use the core BIFs:

microchipOSHI - Operating System + Hardwarechevron-right

🔧 Advanced: Java ProcessBuilder Interop

systemExecute() covers most use cases. When you need streaming output, process pipelines, or interactive I/O, use Java's ProcessBuilder directly via BoxLang's Java interop.

Streaming Process Output

Custom Working Directory & Environment

Inherit Parent I/O (Interactive)

Process Pipeline (Java 9+)

Chain processes so stdout of one feeds stdin of the next:

circle-info

Prefer systemExecute() for straightforward commands — it handles stream draining, timeout, and exit code in a single call. Use ProcessBuilder only when you need streaming I/O, pipelines, or interactive processes.


🔐 Security Considerations

triangle-exclamation

Additional guidelines:

  • Validate paths before passing them to directory, output, or error arguments — prevent path traversal attacks.

  • Use inheritEnvironment=false when spawning processes that should not have access to your application's secrets (API keys, DB passwords in env vars).

  • Disable populateServerSystemScope unless you specifically need bulk access to all env vars; use getSystemSetting() for individual lookups instead.

  • Restrict output file paths — ensure processes cannot write to sensitive locations by validating the output/outputFile arguments.

  • Set timeouts for all externally invoked processes to prevent resource exhaustion.


rectangle-terminalCLI Scriptingchevron-rightcabinet-filingFile Handlingchevron-rightfile-linesProperty Fileschevron-rightcubeVariable Scopeschevron-rightmicrochipOSHI - Operating System + Hardwarechevron-rightzipchevron-rightjavaJava Interopchevron-right

Last updated

Was this helpful?