Module lsh.cmd.status
Describes the result of a process after it has terminated.
This struct holds the exit status of a child process.
The run method of lsh.cmd and the wait method of
lsh.cmd.child return it.
Functions
| new (child[, hang]) | Constructs a new status instance. |
Status methods
| type (self) | Returns the type of the instance. |
| success (self) | Returns true if the process exited with status zero. |
| code (self) | Returns the exit code of the process, if any. |
Functions
- new (child[, hang])
-
Constructs a new status instance.
You do not need to call this function directly. Use lsh.cmd.run or lsh.cmd.spawn.
Parameters:
- child lsh.cmd.child child instance
- hang
bool
block until the process exits (
falseby default) (optional)
Returns:
-
lsh.cmd.status
status
Or
-
boolean
falseif the process did not exit yetOr
- nil
- string error message
Status methods
- type (self)
-
Returns the type of the 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)
-
Returns
trueif the process exited with status zero.If a signal terminated the process, it returns
false.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.
If a signal terminated the process, it returns the signal number.
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