Skip to content

process ​

luau
local process = require("@lute/process")

WARNING

These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.

Summary ​

EntryDescription
ProcessResultThe result of a completed process, including exit code and captured stdout/stderr.
ProcessRunOptionsOptions for process.run:
ProcessSystemOptionsOptions for process.system:
SignalAn operating system signal name.
SignalHandleA handle returned by process.signal. Call :close() to deregister the handler.
StdioKindHow a child process's standard streams should be handled:
argsCommand-line arguments passed to the current script, as an array of strings.
cwdReturns the current working directory as a string.
envA table of environment variables for the current process.
execPathReturns the path of the currently running lute executable as a string.
exitExits the current process with the given exitcode.
homedirReturns the current user's home directory as a string.
onSignalRegisters callback to be called whenever signal is delivered to this process.
pidReturns the PID of the current process.
runRuns the program given by args[1] with the remaining entries as arguments. Returns the process result including exit code and any captured output.
systemRuns command through the system shell. Returns the process result.

Types ​

ProcessResult ​

The result of a completed process, including exit code and captured stdout/stderr.

luau
type ProcessResult = {
	stdout: string,
	stderr: string,

	ok: boolean,
	exitcode: number,
	signal: string?,
	timedOut: boolean?,
}

ProcessRunOptions ​

Options for process.run:

  • cwd: The working directory for the child process. Defaults to the current working directory.

  • stdio: How to handle the child's stdio streams. Defaults to "default".

  • env: Environment variables for the child process. If omitted, inherits the parent's environment.

  • timeout: Maximum time in seconds to wait for the process. If exceeded, the process group is killed.

luau
type ProcessRunOptions = {
	cwd: string?,
	stdio: StdioKind?,

	env: { [string]: string }?,
	timeout: number?,
}

ProcessSystemOptions ​

Options for process.system:

  • system: The shell executable to use. If omitted, uses the platform default ($SHELL on Unix, %COMSPEC% on Windows).

  • cwd: The working directory for the child process. Defaults to the current working directory.

  • stdio: How to handle the child's stdio streams. Defaults to "default".

  • env: Environment variables for the child process. If omitted, inherits the parent's environment.

  • timeout: Maximum time in seconds to wait for the process. If exceeded, the process group is killed.

luau
type ProcessSystemOptions = {
	system: string?,
	cwd: string?,
	stdio: StdioKind?,

	env: { [string]: string }?,
	timeout: number?,
}

Signal ​

An operating system signal name.

Only SIGINT and SIGTERM are guaranteed to be supported on all platforms.

Other signals may be unsupported, but will result in no-op behavior when used.

luau
type Signal =

SignalHandle ​

A handle returned by process.signal. Call :close() to deregister the handler.

luau
type SignalHandle = {
	close: (self: SignalHandle) -> (),
}

StdioKind ​

How a child process's standard streams should be handled:

  • "default": Capture stdout and stderr to pipes, accessible via ProcessResult.

  • "inherit": Pass the parent process's stdio streams through to the child.

  • "none": Discard the child's stdio streams.

luau
type StdioKind = "default" | "inherit" | "none"

Functions and Properties ​

process.args ​

Command-line arguments passed to the current script, as an array of strings.

luau
{ string }

process.cwd ​

Returns the current working directory as a string.

luau
() -> string

process.env ​

A table of environment variables for the current process.

luau
{ [string]: string }

process.execPath ​

Returns the path of the currently running lute executable as a string.

luau
() -> string

process.exit ​

Exits the current process with the given exitcode.

luau
(exitcode: number) -> never

process.homedir ​

Returns the current user's home directory as a string.

luau
() -> string

process.onSignal ​

Registers callback to be called whenever signal is delivered to this process.

Suppresses the default OS behavior (e.g. "SIGINT" will no longer terminate the process).

Returns a handle; call handle:close() to deregister.

luau
(signal: Signal, callback: () -> ()) -> SignalHandle

process.pid ​

Returns the PID of the current process.

luau
() -> number

process.run ​

Runs the program given by args[1] with the remaining entries as arguments. Returns the process result including exit code and any captured output.

luau
(args: { string }, options: ProcessRunOptions?) -> ProcessResult

process.system ​

Runs command through the system shell. Returns the process result.

luau
(command: string, options: ProcessSystemOptions?) -> ProcessResult