@npmcli/promise-spawn
Spawn processes the way the npm cli likes to do. Give it some options,
it'll give you a Promise that resolves or rejects based on the results of
the execution.
USAGE
const promiseSpawn = require('@npmcli/promise-spawn')
promiseSpawn('ls', [ '-laF', 'some/dir/*.js' ], {
cwd: '/tmp/some/path',
stdioString: false,
stdio: 'pipe',
}, {
extra: 'things',
to: 'decorate',
the: 'result',
}).then(result => {
console.log('ok!', result)
}).catch(er => {
console.error('failed!', er)
})
API
Run the command, return a Promise that resolves/rejects based on the
process result.
Result or error will be decorated with the properties in the extra
object. You can use this to attach some helpful info about why the
command is being run, if it makes sense for your use case.
If stdio
is set to anything other than 'inherit'
, then the result/error
will be decorated with stdout
and stderr
values. If stdioString
is
set to true
, these will be strings. Otherwise they will be Buffer
objects.
Returned promise is decorated with the stdin
stream if the process is set
to pipe from stdin
. Writing to this stream writes to the stdin
of the
spawned process.
Options
stdioString
Boolean, default false
. Return stdout/stderr output as
strings rather than buffers.cwd
String, default process.cwd()
. Current working directory for
running the script. Also the argument to infer-owner
to determine
effective uid/gid when run as root on Unix systems.- Any other options for
child_process.spawn
can be passed as well.