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 (false by default) (optional)

Returns:

    lsh.cmd.status status

Or

    boolean false if the process did not exit yet

Or

  1. nil
  2. 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 true if 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
generated by LDoc 1.5.0 Last updated 2026-10-02 09:04:27 UTC (f69ca05)