System Library Reference
The system
library in EasyBite offers a comprehensive suite of functions to interact with the host operating system in a safe, cross‑platform manner. Whereas EasyBite’s core language focuses on computation and data manipulation, the system
library bridges the gap between script and OS—letting you inspect environment variables, manage files and directories, spawn and control processes, query network settings, and detect platform details. By encapsulating these capabilities in pure EasyBite functions, you gain the power of native system calls without abandoning the comfort and security of EasyBite’s runtime.
In modern automation, DevOps, and scripting tasks, a single uniform API that works across Windows, macOS, Linux, Android, and iOS is invaluable. The system
library abstracts away platform‑specific quirks—whether it’s Windows drive letters, Unix mount points, or the difference between which
and where
—so your scripts remain portable. Moreover, all functions return EasyBite Result
types, ensuring that errors (e.g., missing files, permission denied, unreachable hosts) are caught and handled gracefully rather than crashing the interpreter.
Beyond mere convenience, exposing system functionality within EasyBite enables advanced workflows: automatically generating directory trees, orchestrating subprocess pipelines, checking remote server health via ping
, or even performing light port scans. Whether you’re writing build scripts, deployment tools, or quick one‑off automation, the system
library is your standard library companion for everything outside pure computation.
Function | Parameters | Description |
---|---|---|
ENVIRONMENT & WORKING DIRECTORY | ||
getenv(var) | var (String) | Returns the value of environment variable var . |
setenv(var, value) | var , value (Strings) | Sets environment variable var to value . |
currentdir() | — | Returns the current working directory. |
changedir(path) | path (String) | Changes the working directory to path . |
FILE SYSTEM OPERATIONS | ||
listdir(path) | path (String) | Returns an array of entries (filenames) in the directory at path . |
readfile(path) | path (String) | Reads and returns the contents of file at path . |
writefile(path, data) | path , data (Strings) | Writes data to file at path , overwriting if it exists. |
deletefile(path) | path (String) | Deletes the file at path . |
createdir(path) | path (String) | Creates a directory at path . |
deletedir(path) | path (String) | Recursively deletes the directory at path . |
rename(old, new) | old , new (Strings) | Renames or moves a file or directory from old to new . |
copyfile(src, dst) | src , dst (Strings) | Copies file from src to dst . |
DRIVE, VOLUME & OS DETECTION | ||
iswindows() | — | Returns true if running on Windows. |
islinux() | — | Returns true if running on Linux. |
ismacos() | — | Returns true if running on macOS. |
isandroid() | — | Returns true if running on Android. |
isios() | — | Returns true if running on iOS. |
listvolumes() | — | Lists mounted volumes (drive letters on Windows, mount points on Unix/macOS). |
listdrives() | — | On Windows, lists drive letters; otherwise delegates to listvolumes() . |
isappinstalled(app) | app (String) | Checks if app executable is on the system PATH . |
PATH OPERATIONS | ||
joinpath(parts) | parts (Array of Strings) | Joins path components into a single path string. |
splitdrive(path) | path (String) | Splits path into { drive, path } (drive letter on Windows). |
splitpath(path) | path (String) | Splits path into an array of its path components. |
PROCESS INFO & COMMAND EXECUTION | ||
getprocessid() | — | Returns the current process’s PID. |
runcommand(cmd, args) | cmd (String), args (Array of Strings) | Runs cmd with optional args , returns { output, exit_status } . |
spawnprocess(cmd, args) | same as above | Launches a detached process, returns its PID. |
killprocess(pid) | pid (Number) | Kills the process identified by pid . |
FILE/DIR CHECKS & TREE DISPLAY | ||
isfile(path) | path (String) | Returns true if path exists and is a file. |
isdir(path) | path (String) | Returns true if path exists and is a directory. |
gettree(path) | path (String) | Recursively builds a tree representation of path and its children. |
SYSTEM INFORMATION & UTILITY | ||
getsysteminfo() | — | Returns a dictionary with { os, architecture } . |
sleep(ms) | ms (Number) | Blocks the current thread for ms milliseconds. |
NETWORK UTILITIES | ||
getpublicip() | — | Fetches and returns the public IP via an external web service. |
getprivateip() | — | Determines and returns the local IP by opening a UDP socket to 8.8.8.8 . |
getmacaddress() | — | Returns the MAC address of the primary network interface. |
isportopen(ip, port) | ip (String), port (Number) | Checks if port on ip is accepting TCP connections (1 sec timeout). |
listopenports(ip) | ip (String) | Scans ports 1–1024 on ip , returns an array of open port numbers. |
ping(host) | host (String) | Sends a single ping to host ; returns true if successful. |
Detailed Examples
1. getenv(var)
import system
show(system.getenv("HOME"))
Output:
"/home/alice"
2. setenv(var, value)
import system
show(system.setenv("MY_VAR", "123"))
show(system.getenv("MY_VAR"))
Output:
true
"123"
3. currentdir()
import system
show(system.currentdir())
Output:
"/home/alice/projects"
4. changedir(path)
import system
show(system.changedir("/tmp"))
show(system.currentdir())
Output:
true
"/tmp"
5. listdir(path)
import system
show(system.listdir("."))
Output:
["file1.txt", "src", "Cargo.toml"]
6. readfile(path)
import system
show(system.readfile("README.md"))
Output:
"# My Project\n\nThis project does …"
7. writefile(path, data)
import system
show(system.writefile("hello.txt", "Hello, world!"))
show(system.readfile("hello.txt"))
Output:
true
"Hello, world!"
8. deletefile(path)
import system
show(system.deletefile("hello.txt"))
Output:
true
9. createdir(path)
import system
show(system.createdir("my_temp"))
show(system.listdir("."))
Output:
true
["file1.txt", "src", "Cargo.toml", "my_temp"]
10. deletedir(path)
import system
show(system.deletedir("my_temp"))
Output:
true
11. rename(old, new)
import system
show(system.writefile("a.txt", "A"))
show(system.rename("a.txt", "b.txt"))
show(system.listdir("."))
Output:
true
true
["file1.txt", "b.txt", "src", "Cargo.toml"]
12. copyfile(src, dst)
import system
show(system.copyfile("b.txt", "c.txt"))
show(system.readfile("c.txt"))
Output:
true
"A"
13. iswindows()
import system
show(system.iswindows())
Output:
false
14. islinux()
import system
show(system.islinux())
Output:
true
15. ismacos()
import system
show(system.ismacos())
Output:
false
16. isandroid()
import system
show(system.isandroid())
Output:
false
17. isios()
import system
show(system.isios())
Output:
false
18. listvolumes()
import system
show(system.listvolumes())
Output:
["/","/boot","/home"]
19. listdrives()
import system
show(system.listdrives())
Output (Windows example):
["C:\\","D:\\","E:\\"]
20. isappinstalled(app)
import system
show(system.isappinstalled("git"))
show(system.isappinstalled("nonexistent_app"))
Output:
true
false
21. joinpath(parts)
import system
show(system.joinpath(["/usr","local","bin"]))
Output:
"/usr/local/bin"
22. splitdrive(path)
import system
show(system.splitdrive("C:\\Program Files\\App"))
Output:
{ drive: "C:\\", path: "\\Program Files\\App" }
23. splitpath(path)
import system
show(system.splitpath("/usr/local/bin"))
Output:
["/","usr","local","bin"]
24. getprocessid()
import system
show(system.getprocessid())
Output:
4321
25. runcommand(cmd, args)
import system
show(system.runcommand("echo", ["hello"]))
Output:
{ output: "hello\n", exit_status: 0 }
26. spawnprocess(cmd, args)
import system
let pid = system.spawnprocess("sleep", ["10"])
show(pid)
Output:
7654
27. killprocess(pid)
import system
show(system.killprocess(7654))
Output:
true
28. isfile(path)
import system
show(system.isfile("Cargo.toml"))
Output:
true
29. isdir(path)
import system
show(system.isdir("src"))
Output:
true
30. gettree(path)
import system
show(system.gettree("."))
Output:
{ name: ".", path: ".", children: [ … ] }
31. getsysteminfo()
import system
show(system.getsysteminfo())
Output:
{ os: "linux", architecture: "x86_64" }
32. sleep(ms)
import system, math
let t1 = Date.now()
system.sleep(500)
let t2 = Date.now()
show(t2 - t1)
Output (approximate):
500
33. getpublicip()
import system
show(system.getpublicip())
Output:
"203.0.113.45"
34. getprivateip()
import system
show(system.getprivateip())
Output:
"192.168.1.12"
35. getmacaddress()
import system
show(system.getmacaddress())
Output:
"00:1A:2B:3C:4D:5E"
36. isportopen(ip, port)
import system
show(system.isportopen("127.0.0.1", 22))
Output:
true
37. listopenports(ip)
import system
show(system.listopenports("127.0.0.1"))
Output:
[22, 80, 443]
38. ping(host)
import system
show(system.ping("google.com"))
Output:
true