Skip to content

junyulah/spawnp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spawnp

node spawn but return promise.

Build Status

Coverage Status

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(''));
});

About

node spawn return promise

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published