Module lsh.cmd.status
Describes the result of a process after it has terminated.
This struct is used to represent the exit status of a child process.
Child processes are created via the lsh.cmd struct and their exit
status is exposed through the run
method, or the wait
method of
a lsh.cmd.child process.
Functions
new (child[, hang]) | Constructs the new status instance. |
Status methods
type (self) | Returns the type of a instance. |
success (self) | Was termination successful? |
code (self) | Returns the exit code of the process, if any. |
Functions
- new (child[, hang])
-
Constructs the new status instance.
There is no need to use this method directly, see lsh.cmd.run and lsh.cmd.spawn for practical program execution.
Parameters:
- child lsh.cmd.child child instance
- hang bool hang by default (optional)
Returns:
-
lsh.cmd.status
status
Or
-
boolean
false if process didn't terminate
Status methods
- type (self)
-
Returns the type of a instance.
Parameters:
- self lsh.cmd.status
Returns:
-
the string
"cmd_status"
Usage:
local sh = require 'lsh' assert(sh.cmd('ls'):run():type() == 'cmd_status')
- success (self)
-
Was termination successful?
Signal termination is not considered a success, and success is defined as a zero exit status.
Parameters:
- self lsh.cmd.status
Returns:
-
bool
Usage:
local sh = require 'lsh' local status = sh.cmd('mkdir'):arg('projects') :run() if status:success() then print('"projects/" directory created') else print('failed to create "projects/" directory') end
- code (self)
-
Returns the exit code of the process, if any.
It will return
nil
if the process was terminated by a signal.Parameters:
- self lsh.cmd.status
Returns:
-
number
Or
-
nil
Usage:
local sh = require 'lsh' local status = sh.cmd('mkdir'):arg('projects') :run() local code = status:code() if code then print(("Exited with status code: %d"):format(code)) else print('Process terminated by signal') end