项目作者: strugee

项目描述 :
Spawn an async process and get back stdout, handling errors
高级语言: JavaScript
项目地址: git://github.com/strugee/node-smart-spawn.git
创建时间: 2016-10-30T00:19:00Z
项目社区:https://github.com/strugee/node-smart-spawn

开源协议:GNU Lesser General Public License v3.0

下载


smart-spawn

Build Status
Coverage Status
npm
Greenkeeper badge

Spawn an async process and get back stdout, handling errors

Installation

  1. npm install smart-spawn

Usage

You need Node 6+. It’ll probably run on 0.10, 0.12 and 4 too, but the test suite doesn’t cover those versions, so you’re on your own. And you should upgrade anyway because those are horribly insecure.

  1. var smartSpawn = require('smart-spawn');
  2. var process = smartSpawn('ls', ['-l'], process.cwd(), function(err, stdout) {
  3. if (err) throw err;
  4. console.log(stdout);
  5. }

Arguments

Arguments are, in order: the name of the process to spawn, arguments passed to the subprocess, the subprocess’ working directory, and a callback function.

The callback receives two arguments. The first is an Error object which is passed if the process couldn’t be spawned or if it exited with a nonzero exit code, otherwise it’s undefined. The second is the process’ stdout upon its completion (regardless of any errors that may have occured).

Return value

smart-spawn will return an instance of ChildProcess representing the spawned subprocess.

License

LGPL 3.0+

Author

AJ Jordan alex@strugee.net