Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

superspawn

marcdiethelm1.2kApache0.1.0

A Node.js spawn command that works on Windows too

run, cmd, spawn, windows, child, process, child_process, promise

readme

Build status (master)   npm version

superspawn

A Node.js spawn command that works on Windows too.

Original source from Apache Cordova's superspawn.js by Andrew Grieve. Requires Node.js 0.10+.

Windows extras
  • Sets '/c' flag so files other than .exe can be run. Supported: .exe, .cmd, .bat, .js, .vbs
  • Sets '/s' flags so commands (and paths) containing spaces or quotes are parsed correctly.

See this Node bug.

Install

npm i --save superspawn

Usage

Superspawn uses the same signature as the native child_process.spawn. But instead of a reference to the child process it returns a Q.promise or undefined if a callback is passed.

API

var spawn = require('superspawn').spawn

/**
 * A windows-compatible spawn method. Succeeds for child exit code === 0.
 * @param {string} cmd
 * @param {string[]} [args]
 * @param {opts} [opts]
 * @param {function} [callback] - standard Node callback, omit if you want to use a promise.
 * @returns {Q.promise|undefined} - returns a promise or undefined if a callback is passed.
 *
 * @typedef {Object} opts
 * @property {boolean} [printCommand=false] - Whether to log the command
 * @property {string} stdio -
 *     'default' is to capture output and returning it as a string to success (same as exec).
 *     'ignore' means don't bother capturing it.
 *     'inherit' means pipe the input & output. This is required for anything that prompts.
 * @property {object} env - Map of extra environment variables.
 * @property {string} cwd - Working directory for the command.
 */
spawn(cmd, args, opts, function(err, output) {
    if (err) return err;
});

// or

spawn(cmd, args, opts)
    .catch(function(err) {}) // rejectedHandler
    .then(function(stdout) {}) // resolvedHandler
;

Examples

spawn('echo', ['buffalo'], function(err, output) {
    if (err) return err;
    assert.equal(output, 'buffalo');
});

spawn('./script.sh', 'inherit', function(err) {
    if (err) return err;
});

Todo

  • <input disabled="" type="checkbox"> Write tests

changelog

Changelog

0.1.0 — 2014-05-04

  • Fix Windows issues: execute native commands, execute *.js files.
  • You can pass a standard callback. Instead of returning a Q.promise the return will be undefined.
  • Adds basic tests.

0.0.2 — 2014-04-28

  • Remove stdout capture for stdio 'inherit'. It removed color from the output and broke Inquirer.js' 'checkbox' prompt. And it is not what the user expects anyway, even though it would be very nice to have.

0.0.1 — 2014-04-26

  • Copy Apache Cordova coho's superspawn.js. Add npm/node module stuff.
  • Fix a stdio config bug.
  • Replace shelljs(.which) with module 'which'.