Table of Contents
spawn
Spawn a new process from an executable image
Parameters
image
string The executable code to run (optional, default""
)argv
array Argument vector for the new process (optional, default[]
)
Examples
sys.spawn("console.log(argv)", ["hello", "world"])
Returns Promise<number> pid - The ID of the new process
exec
Spawn a new process from a path
Parameters
Examples
sys.exec("/bin/ls", ["ls", "-a"])
exists
Check if a file exists
Parameters
path
string
Examples
const exists = await sys.exists("/file")
stat
Get file/directory info
Parameters
path
string
Examples
const info = await sys.stat("/file")
open
Open a file/directory to get its file descriptor
Parameters
path
stringmode
(optional, default"r"
)
Examples
const fd = await sys.open("/file")
Returns Promise<number> fd - new file descriptor
close
Close a file descriptor from use
Parameters
fd
number
Examples
sys.close(3)
dup
Duplicate a file descriptor
Parameters
fd
number File descriptor to copy
Examples
const copied = await sys.dup(0)
Returns Promise<number> duplicated file descriptor
dup2
Duplicate a file descriptor to a new location, possibly overwriting one
Parameters
Examples
sys.dup2(1, 2)
Returns Promise<number> Second file descriptor
read
Read file contents from a file descriptor
Parameters
fd
number
Examples
const contents = await sys.read(fd)
Returns Promise<string> data - file contents
write
Write data to a file descriptor
Parameters
Examples
sys.write(1, "hello world")
pwd
Get the currect working directory
Examples
const cwd = await sys.pwd()
Returns Promise<string> current working directory
chdir
Change the working directory
Parameters
path
string new working directory (optional, default"/home"
)
Examples
sys.chdir("/home")
getenv
Get an environment variable value by key, invoke with no arguments to return the whole environment variable object
Parameters
key
string
Examples
const usingAwait = (await sys.getenv("PATH")).split(":")
const usingPromise = sys.getenv("PATH").then(path => path.split(":"))
setenv
Set an environment variable to a new value
Parameters
Examples
sys.setenv("varName", "It doesn't have to be all caps")