Process
A built-in library that interacts with the system process.
Properties
Functions
Properties
os
process.os: "linux" | "windows" | "macos"
The operating system that the process is running on.
arch
process.arch: "aarch64" | "x86_64" | "riscv64"
The cpu architecture that the process is running on. This property can have more possible values (Usually from a custom zune build for another architecture). It would be nice if you can consider other kinds of architectures.
cwd
process.cwd: string
The current working directory of the process.
args
process.args: { string }
The arguments passed to the process.
env
process.env: { [string]: string }
The EnvironmentMap of the process.
Order of files loaded:
- Includes
.env
file in the current working directory. - Includes
.env.production
file in the current working directory. WhenLUAU_ENV
is set toPRODUCTION
. - Includes
.env.development
file in the current working directory.When LUAU_ENV
is set toDEVELOPMENT
. - Includes
.env.test
file in the current working directory. WhenLUAU_ENV
is set toTEST
. - Includes
.env.local
file in the current working directory.
Functions
loadEnv
process.loadEnv(): { [string]: string }
Same behavior as process.env
, does not update process.env
.
Returns
{ [string]: string }
- The EnvironmentMap of the process.
create
process.create(exec: string, args: { string }?, options: ProcessOptions?): (boolean, ProcessChild | string)
Creates a new process.
Parameters
exec: string
- The executable to run.args: { string }?
- The arguments to pass to the executable.options:
ProcessOptions
- The options for the process.
Returns
boolean
- If the operation was successful.ProcessChild
|string
- The process handle or an error.
run
process.run(exec: string, args: { string }?, options: ProcessOptions?): (boolean, ProcessRunResult | string)
Runs a new process.
Blocks the current process until the process has exited.
We recommend using process.create
for non-blocking process creation.
Parameters
exec: string
- The executable to run.args: { string }?
- The arguments to pass to the executable.options:
ProcessOptions
- The options for the process.
Returns
boolean
- If the operation was successful.ProcessRunResult
|string
- The process handle or an error.
exit
process.exit(code: number): ()
Exits the current process.
Parameters
code: number
- The exit code.
onSignal
process.onSignal(signal: "INT", callback: () -> ()): ()
Registers a signal handler.
Supported signals:
INT
- Interrupt signal (SIGINT).
Parameters
signal: "INT"
- The signal to handle.callback: () -> ()
- The callback to run when the signal is received.
Types
ProcessOptions
export type ProcessOptions = {
cwd: string?,
env: { [string]: string }?,
shell: (boolean | string)?,
}
ProcessResult
export type ProcessResult = {
ok: boolean,
code: number,
status: "Exited" | "Stopped" | "Signal" | "Unknown",
}
ProcessRunResult
export type ProcessRunResult = ProcessResult & {
stdout: string,
stderr: string,
}
ProcessChild
export type ProcessChild = userdata<{
--[[
Waits for the process to exit. Calls system function.
Does not yield, **blocks** process.
@return ProcessResult
]]
wait: (self: ProcessChild) -> ProcessResult,
--[[
Kills process. Calls system function.
Does not yield, **blocks** process.
@return ProcessResult
]]
kill: (self: ProcessChild) -> ProcessResult,
--[[
Reads the output of the process. Stdout.
Optional size parameter to read a specific amount of bytes.
Nil to read all.
@param size The size of the output to read.
@return string
]]
readOut: (self: ProcessChild, size: number?) -> string,
--[[
Writes to the input of the process. Stdin.
@param data The data to write to the process.
]]
writeIn: (self: ProcessChild, data: string) -> (),
--[[
Reads the error output of the process. Stderr.
Optional size parameter to read a specific amount of bytes.
Nil to read all.
@param size The size of the output to read.
@return string
]]
readErr: (self: ProcessChild, size: number?) -> string,
}>