Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

uji.job

uji.job runs a process in the background and streams its output to Lua.

uji.job.start(opts)

Starts a process and returns a job table.

OptionTypeMeaning
cmdstring or listRequired. A string runs through sh -c. A list is the program and its arguments.
cwdstringThe directory to run in. The default is uji’s working directory.
timeoutnumberSeconds before uji kills the process.
on_stdoutfunctionReceives each line the process writes to standard output.
on_stderrfunctionReceives each line the process writes to standard error.
on_exitfunctionReceives the exit code. When uji stopped the process, it receives -1 and "timeout" or "stopped".

The job table has three functions:

  • job.send(text) writes a line to the process’s standard input, adding a newline if text lacks one.
  • job.close() closes standard input.
  • job.stop() kills the process.

Raises an error when cmd is missing or empty.

local job = uji.job.start({
  cmd = { "git", "status", "--short" },
  on_stdout = function(line)
    uji.notify(line)
  end,
  on_exit = function(code)
    if code ~= 0 then
      uji.notify("git status failed with " .. code)
    end
  end,
})
job.close()