there is no
guarantee that libuv can discover all file descriptors that
were inherited. In general it does a better job on Windows
than it does on Unix.
uv.spawn({path}, {options}, {on_exit}) *uv.spawn()*
Parameters:
- `path`: `string`
- `options`: `table` (see below)
- `on_exit`: `callable`
- `code`: `integer`
- `signal`: `integer`
Initializes the process handle and starts the process. If the
process is successfully spawned, this function will return the
handle and pid of the child process.
Possible reasons for failing to spawn would include (but not
be limited to) the file to execute not existing, not having
permissions to use the setuid or setgid specified, or not
having enough memory to allocate for the new process.
>lua
local stdin = uv.new_pipe()
local stdout = uv.new_pipe()
local stderr = uv.new_pipe()
print("stdin", stdin)
print("stdout", stdout)
print("stderr", stderr)
local handle, pid = uv.spawn("cat", {
stdio = {stdin, stdout, stderr}
}, function(code, signal) -- on exit
print("exit code", code)
print("exit signal", signal)
end)
print("process opened", handle, pid)
uv.read_start(stdout, function(err, data)
assert(not err, err)
if data then
print("stdout chunk", stdout, data)
else
print("stdout end", stdout)
end
end)
uv.read_start(stderr, function(err, data)
assert(not err, err)
if data then
print("stderr chunk", stderr, data)
else
print("stderr end", stderr)
end
end)
uv.write(stdin, "Hello World")
uv.shutdown(stdin, function()
print("stdin shutdown", stdin)
uv.close(handle, function()
print("process closed", handle, pid)
end)
end)
<
*uv.spawn-options*
The `options` table accepts the following fields:
- `options.args` - Command line arguments as a list of
strings. The first string should not be the path to the
program, since that is already provided via `path`. On
Windows, this uses CreateProcess which concatenates the
arguments into a string. This can cause some strange
errors (see `options.verbatim` below for Windows).
- `options.stdio` - Set the file descriptors that will be
made available to the child process. The convention is
that the first entries are stdin, stdout, and stderr.
(Note: On Windows, file descriptors after the third are
available to the child process only if the child processes
uses the MSVCRT runtime.)
- `options.env` - Set environment variables for the new
process.
- `options.cwd` - Set the current working directory for the
sub-process.
- `options.uid` - Set the child process' user id.
- `options.gid` - Set