spawnp
v0.1.2
Published
node spawn return promise
Downloads
40
Readme
spawnp
node spawn but return promise.
install
npm i spawnp --save
example
let spawnp = require('spawnp');
spawnp('echo', ['123']).then(() => {
// finshed
}).catch(() => {
// erorred
});
api
spawnp(command[, args][, options][, extra])
- command
Just like spawn's command, but support arg in command, like echo 123
spawnp('echo 123', ['456']); // 123 456\n
- args
Just like spawn's args
- options
Just like spawn's options
- extra
Object, {onChild, stdout, stderr}, see next.
onChild
spawnp('echo', ['123'], null, {
onChild: (child) => {
child.stdout.on('data', (chunk) => {
console.log(chunk.toString()); //123\n
});
};
}); // return a promise
stdout
spawnp('echo', ['123'], null, {
stdout: true // config stdout option
}).then(({
stdouts // then will get stdout chunks
}) => {
console.log(stdouts.join('')); //'123\n';
});
stderr
spawnp('ls', ['oooooooooo'], null, {
stderr: true
}).catch(({
stderrs
}) => {
console.log(stderrs.join(''));
});