capinexec

function capinexec( cmd [, outfile [, errfile]] ) --> exit, signal

Description

Executes a shell command cmd and allows to capturethe output of stdout in outfile and stderr in errfile optionally. If only outfile is defined, writes the functions stdout and stderr to outfile.

Parameters

cmd

A shell command.

outfile

Optional path to a file. The file must not exist.

errfile

Optional path to file. The file must not exist.

Return Values

exit

The exit status of the command, if it terminated normally.

signal

The signal that terminated the command, if it was terminated by a signal.

Code

--ZFUNC-capinexec-v1
local function capexec( cmd, outfile, errfile ) --> exit, signal
   local outpipe = ''
   if outfile then outpipe = ' >"'..outfile'"' end
   local errpipe = ''
   if errfile then errpipe = ' 2>"'..errfile'"'
   else  errpipe = ' 2>&1' end
   return os.execute( cmd..outpipe..errpipe )
end

return capexec

See also