External commands

Synopsis

luakit.spawn(command)
rv, out, err = luakit.spawn_sync(command)

Description

luakit.spawn() executes a command asynchronously. It is unable to retrieve any information from the spawned process, like exit status or standard output.

luakit.spawn_sync() executes a command synchronously. It returns the tuple (exit_code, standard_output, standard_error).

Argument

command is parsed with shell-like parser. For example:

luakit.spawn('dd if=/dev/random of=/dev/mem')

will execute:
arg[0]="dd" 
arg[1]="if=/dev/random" 
arg[2]="of=/dev/mem" 

while

luakit.spawn('rm -rf /etc/* "$(find /var/lib)"')

will execute:
arg[0]="rm" 
arg[1]="-rf" 
arg[2]="/etc/*" 
arg[3]="$(find /var/lib)" 

so it understands (double)quotes, but no shell substitution is performed. See glib g-shell-parse-argv() documentation for more details.

Return values

luakit.spawn() does not return anything
luakit.spawn_sync() returns three values: (rv, out, err)
  • rv is an integer containing exit status of the command
  • out is a string containing all data that command printed on standard output
  • err is a string containing all data that command printed on standard error

Examples

local exit_status, stdout, stderr = luakit.spawn_sync("ls")
print(stdout)

Also available in: HTML TXT