2021-06-25 08:25:05 +02:00
|
|
|
---@meta
|
|
|
|
|
|
|
|
---
|
|
|
|
---Functionality that allows you to launch subprocesses and read
|
|
|
|
---or write to them in a non-blocking fashion.
|
|
|
|
---@class process
|
|
|
|
process = {}
|
|
|
|
|
|
|
|
---Error triggered when the stdout, stderr or stdin fails while reading
|
|
|
|
---or writing, its value is platform dependent, so the value declared on this
|
|
|
|
---interface does not represents the real one.
|
|
|
|
---@type integer
|
|
|
|
process.ERROR_PIPE = -1
|
|
|
|
|
|
|
|
---Error triggered when a read or write action is blocking,
|
|
|
|
---its value is platform dependent, so the value declared on this
|
|
|
|
---interface does not represents the real one.
|
|
|
|
---@type integer
|
|
|
|
process.ERROR_WOULDBLOCK = -2
|
|
|
|
|
|
|
|
---Error triggered when a process takes more time than that specified
|
|
|
|
---by the deadline parameter given on process:start(),
|
|
|
|
---its value is platform dependent, so the value declared on this
|
|
|
|
---interface does not represents the real one.
|
|
|
|
---@type integer
|
|
|
|
process.ERROR_TIMEDOUT = -3
|
|
|
|
|
|
|
|
---Error triggered when trying to terminate or kill a non running process,
|
|
|
|
---its value is platform dependent, so the value declared on this
|
|
|
|
---interface does not represents the real one.
|
|
|
|
---@type integer
|
2021-06-30 09:02:01 +02:00
|
|
|
process.ERROR_INVAL = -4
|
|
|
|
|
|
|
|
---Error triggered when no memory is available to allocate the process,
|
|
|
|
---its value is platform dependent, so the value declared on this
|
|
|
|
---interface does not represents the real one.
|
|
|
|
---@type integer
|
|
|
|
process.ERROR_NOMEM = -5
|
2021-06-25 08:25:05 +02:00
|
|
|
|
|
|
|
---Used for the process:close_stream() method to close stdin.
|
|
|
|
---@type integer
|
|
|
|
process.STREAM_STDIN = 0
|
|
|
|
|
|
|
|
---Used for the process:close_stream() method to close stdout.
|
|
|
|
---@type integer
|
|
|
|
process.STREAM_STDOUT = 1
|
|
|
|
|
|
|
|
---Used for the process:close_stream() method to close stderr.
|
|
|
|
---@type integer
|
|
|
|
process.STREAM_STDERR = 2
|
|
|
|
|
|
|
|
---Instruct process:wait() to wait until the process ends.
|
|
|
|
---@type integer
|
|
|
|
process.WAIT_INFINITE = -1
|
|
|
|
|
|
|
|
---Instruct process:wait() to wait until the deadline given on process:start()
|
|
|
|
---@type integer
|
|
|
|
process.WAIT_DEADLINE = -2
|
|
|
|
|
2021-10-04 06:32:48 +02:00
|
|
|
---Default behavior for redirecting streams.
|
|
|
|
---This flag is deprecated and for backwards compatibility with reproc only.
|
|
|
|
---The behavior of this flag may change in future versions of Lite XL.
|
2021-06-30 09:02:01 +02:00
|
|
|
---@type integer
|
|
|
|
process.REDIRECT_DEFAULT = 0
|
|
|
|
|
2021-10-04 06:32:48 +02:00
|
|
|
---Allow Process API to read this stream via process:read functions.
|
2021-06-30 09:02:01 +02:00
|
|
|
---@type integer
|
|
|
|
process.REDIRECT_PIPE = 1
|
|
|
|
|
2021-10-04 06:32:48 +02:00
|
|
|
---Redirect this stream to the parent.
|
2021-06-30 09:02:01 +02:00
|
|
|
---@type integer
|
|
|
|
process.REDIRECT_PARENT = 2
|
|
|
|
|
2021-10-04 06:32:48 +02:00
|
|
|
---Discard this stream (piping it to /dev/null)
|
2021-06-30 09:02:01 +02:00
|
|
|
---@type integer
|
|
|
|
process.REDIRECT_DISCARD = 3
|
|
|
|
|
2021-10-04 06:32:48 +02:00
|
|
|
---Redirect this stream to stdout.
|
|
|
|
---This flag can only be used on process.options.stderr.
|
2021-06-30 09:02:01 +02:00
|
|
|
---@type integer
|
|
|
|
process.REDIRECT_STDOUT = 4
|
|
|
|
|
|
|
|
---@alias process.errortype
|
|
|
|
---|>'process.ERROR_PIPE'
|
|
|
|
---| 'process.ERROR_WOULDBLOCK'
|
|
|
|
---| 'process.ERROR_TIMEDOUT'
|
|
|
|
---| 'process.ERROR_INVAL'
|
|
|
|
---| 'process.ERROR_NOMEM'
|
|
|
|
|
|
|
|
---@alias process.streamtype
|
|
|
|
---|>'process.STREAM_STDIN'
|
|
|
|
---| 'process.STREAM_STDOUT'
|
|
|
|
---| 'process.STREAM_STDERR'
|
|
|
|
|
|
|
|
---@alias process.waittype
|
|
|
|
---|>'process.WAIT_INFINITE'
|
|
|
|
---| 'process.WAIT_DEADLINE'
|
|
|
|
|
|
|
|
---@alias process.redirecttype
|
|
|
|
---|>'process.REDIRECT_DEFAULT'
|
|
|
|
---| 'process.REDIRECT_PIPE'
|
|
|
|
---| 'process.REDIRECT_PARENT'
|
|
|
|
---| 'process.REDIRECT_DISCARD'
|
|
|
|
---| 'process.REDIRECT_STDOUT'
|
|
|
|
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
--- Options that can be passed to process.start()
|
|
|
|
---@class process.options
|
|
|
|
---@field public timeout number
|
|
|
|
---@field public cwd string
|
|
|
|
---@field public stdin process.redirecttype
|
|
|
|
---@field public stdout process.redirecttype
|
|
|
|
---@field public stderr process.redirecttype
|
|
|
|
---@field public env table<string, string>
|
|
|
|
process.options = {}
|
2021-06-25 08:25:05 +02:00
|
|
|
|
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---Create and start a new process
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@param command_and_params table First index is the command to execute
|
|
|
|
---and subsequente elements are parameters for the command.
|
|
|
|
---@param options process.options
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return process | nil
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
|
|
|
function process:start(command_and_params, options) end
|
2021-06-25 08:25:05 +02:00
|
|
|
|
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---Translates an error code into a useful text message
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@param code integer
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return string | nil
|
|
|
|
function process.strerror(code) end
|
2021-06-25 08:25:05 +02:00
|
|
|
|
|
|
|
---
|
|
|
|
---Get the process id.
|
|
|
|
---
|
|
|
|
---@return integer id Process id or 0 if not running.
|
|
|
|
function process:pid() end
|
|
|
|
|
2021-06-30 09:02:01 +02:00
|
|
|
---
|
|
|
|
---Read from the given stream type, if the process fails with a ERROR_PIPE it is
|
|
|
|
---automatically destroyed returning nil along error message and code.
|
|
|
|
---
|
|
|
|
---@param stream process.streamtype
|
|
|
|
---@param len? integer Amount of bytes to read, defaults to 2048.
|
|
|
|
---
|
|
|
|
---@return string | nil
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
|
|
|
function process:read(stream, len) end
|
|
|
|
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
|
|
|
---Read from stdout, if the process fails with a ERROR_PIPE it is
|
2021-06-30 09:02:01 +02:00
|
|
|
---automatically destroyed returning nil along error message and code.
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@param len? integer Amount of bytes to read, defaults to 2048.
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return string | nil
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
|
|
|
function process:read_stdout(len) end
|
2021-06-25 08:25:05 +02:00
|
|
|
|
|
|
|
---
|
|
|
|
---Read from stderr, if the process fails with a ERROR_PIPE it is
|
2021-06-30 09:02:01 +02:00
|
|
|
---automatically destroyed returning nil along error message and code.
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@param len? integer Amount of bytes to read, defaults to 2048.
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return string | nil
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
|
|
|
function process:read_stderr(len) end
|
2021-06-25 08:25:05 +02:00
|
|
|
|
|
|
|
---
|
|
|
|
---Write to the stdin, if the process fails with a ERROR_PIPE it is
|
2021-06-30 09:02:01 +02:00
|
|
|
---automatically destroyed returning nil along error message and code.
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
|
|
|
---@param data string
|
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return integer | nil bytes The amount of bytes written or nil if error
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
2021-06-25 08:25:05 +02:00
|
|
|
function process:write(data) end
|
|
|
|
|
|
|
|
---
|
|
|
|
---Allows you to close a stream pipe that you will not be using.
|
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@param stream process.streamtype
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return integer | nil
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
2021-06-25 08:25:05 +02:00
|
|
|
function process:close_stream(stream) end
|
|
|
|
|
|
|
|
---
|
|
|
|
---Wait the specified amount of time for the process to exit.
|
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@param timeout integer | process.waittype Time to wait in milliseconds,
|
|
|
|
---if 0, the function will only check if process is running without waiting.
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return integer | nil exit_status The process exit status or nil on error
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
2021-06-25 08:25:05 +02:00
|
|
|
function process:wait(timeout) end
|
|
|
|
|
|
|
|
---
|
|
|
|
---Sends SIGTERM to the process
|
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return boolean | nil
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
2021-06-25 08:25:05 +02:00
|
|
|
function process:terminate() end
|
|
|
|
|
|
|
|
---
|
|
|
|
---Sends SIGKILL to the process
|
|
|
|
---
|
2021-06-30 09:02:01 +02:00
|
|
|
---@return boolean | nil
|
|
|
|
---@return string errmsg
|
|
|
|
---@return process.errortype | integer errcode
|
2021-06-25 08:25:05 +02:00
|
|
|
function process:kill() end
|
|
|
|
|
2021-06-30 09:02:01 +02:00
|
|
|
---
|
|
|
|
---Get the exit code of the process or nil if still running.
|
|
|
|
---
|
|
|
|
---@return number | nil
|
|
|
|
function process:returncode() end
|
|
|
|
|
2021-06-25 08:25:05 +02:00
|
|
|
---
|
|
|
|
---Check if the process is running
|
|
|
|
---
|
|
|
|
---@return boolean
|
|
|
|
function process:running() end
|