OS 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
server Scope — OS Quick ReferenceThe 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
server.osOperating system details sourced from Java system properties and the network stack.
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
server.separatorPath and line separator characters for the current OS — useful for portable file path construction.
file
/
\
File path separator
path
:
;
Path list separator (like $PATH)
line
\n
\r\n
Line ending character(s)
server.java
server.javaJVM runtime information.
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
server.cliCLI invocation details. args and parsed are only populated when running in CLI mode; they are empty string/struct in web/lambda contexts.
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
server.systemAll Java system properties and OS environment variables. Disabled by default for security — enable in boxlang.json:
When enabled:
server.system.environment and server.system.properties expose all environment variables and Java system properties to your code. Only enable populateServerSystemScope when you need bulk access. For targeted lookups, use getSystemSetting() instead.
server.boxlang
server.boxlangBoxLang runtime metadata.
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
systemExecute() BIFExecute any system process and capture its output.
Arguments:
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:
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:
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
bx:execute ComponentThe component version of systemExecute(). Results are distributed into separate named variables rather than returned as a struct.
Attributes:
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
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] )
getSystemSetting( key [, defaultValue] )Retrieve a Java system property or OS environment variable by name.
Lookup order:
Registered system setting providers (by namespace)
Java system properties (
System.getProperties())OS environment variables (
System.getenv())defaultValue— or throwsBoxRuntimeExceptionif none provided
Notes:
Key names are case-sensitive
Namespace support via
.separator (e.g., custom provider registered undermyapp)
Use getSystemSetting() for targeted lookups. It is more secure than enabling server.system scope population, since it does not expose all environment variables to templates.
.env File Auto-Loading (CLI)
.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:
~/.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():
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
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] )
getTickCount( [unit] )Returns a high-resolution system timer value. Default unit is "milli".
"milli" (default)
System.currentTimeMillis() — wall-clock milliseconds
"nano"
System.nanoTime() — monotonic nanoseconds
"second"
Current time in seconds
sleep( duration )
sleep( duration )Pauses the current thread for duration milliseconds. Throws BoxRuntimeException if the thread is interrupted.
ℹ️ System & Runtime Information
getBoxVersionInfo()
getBoxVersionInfo()Returns a struct with BoxLang runtime version details.
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 )
fileInfo( file ) / getFileInfo( file )Both BIFs inspect a file or directory path. getFileInfo() is the verbose alias with additional OS-level attributes.
fileInfo() returns:
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):
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
bx-oshiThe bx-oshi module wraps the OSHI library to expose hardware and OS metrics with no native library requirements.
Convenience BIFs
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:
OSHI - Operating System + Hardware🔧 Advanced: Java ProcessBuilder Interop
ProcessBuilder InteropsystemExecute() 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:
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
Command Injection — Never build command strings by concatenating user-supplied input. Always use array arguments so each token is passed directly to the OS without shell interpretation.
Additional guidelines:
Validate paths before passing them to
directory,output, orerrorarguments — prevent path traversal attacks.Use
inheritEnvironment=falsewhen spawning processes that should not have access to your application's secrets (API keys, DB passwords in env vars).Disable
populateServerSystemScopeunless you specifically need bulk access to all env vars; usegetSystemSetting()for individual lookups instead.Restrict output file paths — ensure processes cannot write to sensitive locations by validating the
output/outputFilearguments.Set timeouts for all externally invoked processes to prevent resource exhaustion.
🔗 Related Documentation
CLI ScriptingFile HandlingProperty FilesVariable ScopesOSHI - Operating System + HardwarezipJava InteropLast updated
Was this helpful?
