How to use the child_process.spawn.apply function in child_process

To help you get started, we’ve selected a few child_process examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github weisjohn / sleepyhollow-node / index.js View on Github external
function sleepyhollow() {

    // the modified event-emitter bridge
    var sleepyhollow = new EventEmitter();
    _emit = sleepyhollow.emit;
    sleepyhollow.emit = function(event, message) {
        if (event !== "ack") write({ event: event, message : message });
        _emit.apply(sleepyhollow, Array.prototype.slice.call(arguments, 0));
    }

    // the phantomjs process
    var args = Array.prototype.slice.call(arguments, 0);
    var phantomjs = spawn.apply(null, ['phantomjs', args]);

    // if node goes down, don't leave phantom zombied
    var exited = false;
    process.on('exit', function() {
        if (!exited) process.kill(phantomjs.pid, 'SIGINT');
    });

    // special listener to the child process lifecycle
    phantomjs.on('exit', function() {
        exited = true;
        sleepyhollow.emit('exit');
    });

    // we use the stderr channel for communication because we listen on
    // stdout for errors and debugging statements
    phantomjs.stderr.on('data', function(data) {
github laverdet / js-xml-literal / test / run-tests.js View on Github external
function runCommand(executable, args) {
    if (executable) {
      pending.push([executable, args]);
    }
    if (!proc && pending.length) {
      proc = spawn.apply(null, pending.shift());

      proc.stdout.on('data', function(data) {
        util.print(data);
      });

      proc.stderr.on('data', function(data) {
        util.print(data);
      });

      proc.on('exit', function(code) {
        if (code) {
          util.print('exited with code ' + code + '\n');
        }
        proc = null;
        runCommand();
      });
github timoxley / npm-run / spawn.js View on Github external
npmPath.set({cwd: options.cwd, env: process.env}, function(err) {
  options.stdio = 'inherit'
  spawn.apply(null, args)
  .once('error', function(err) {
    if (err.code === 'ENOENT') {
      err.cmd = args.slice(0, -1).join(' ')
      err.message = 'Invalid npm-run command: ' + err.cmd
    }
    process.send(serializerr(err))
  })
  .on('close', function(code) {
    process.exit(code)
  })
})
github twilio / twilio-video.js / gulpfile.js View on Github external
function safeSpawn() {
  var child = spawn.apply(this, arguments);
  safeSpawn._children.push(child);
  return child;
}
github jamesshore / lets_code_javascript / node_modules / karma / lib / launchers / process.js View on Github external
var spawnWithoutOutput = function () {
      var proc = spawn.apply(null, arguments)
      proc.stdout.resume()
      proc.stderr.resume()

      return proc
    }
github twilio / twilio-common.js / gulpfile.js View on Github external
function safeSpawn() {
  var child = spawn.apply(this, arguments);
  safeSpawn._children.push(child);
  return child;
}
github shama / napa / lib / pkg.js View on Github external
function gitInstall () {
    var args = ['clone', '--depth', '1', '-q', (self.url.replace('git+', '')), self.installTo]
    var cmd = ['git', args]
    if (self.ref) args.splice(1, 2)
    if (typeof self._mock === 'function') {
      self._mock(cmd)
    } else {
      self.log.info('git', '%s into %s', self.url, self.name)
      var git = spawn.apply(spawn, cmd)
      git.stderr.on('data', log.error)
      git.on('close', function (code, signal) {
        var checkout
        if (code) return cb(code, signal)
        if (self.ref) {
          checkout = spawn('git', ['checkout', self.ref], {cwd: self.installTo})
          checkout.stderr.on('data', log.info)
          checkout.on('close', function () {
            rimraf(path.resolve(self.installTo, '.git'), cb)
          })
        } else {
          rimraf(path.resolve(self.installTo, '.git'), cb)
        }
      })
    }
  }
github racker / node-rproxy / node_modules / rackspace-shared-utils / lib / misc.js View on Github external
exports.spawnChild = function spawnChild(binPath, args, options, cacheKey,
                                         readyMessage, printStdout, printStderr) {
  var child, spawnArgs, stdoutBuffer, stderrBuffer,
      timeoutId = null, readyEmitted = false;

  args = args || [];
  spawnArgs = [binPath, args];

  if (options) {
    spawnArgs.push(options);
  }

  child = spawn.apply(this, spawnArgs);

  function emitReadyFunc(err) {
    if (!readyEmitted) {
      readyEmitted = true;
      emitReady(cacheKey, child, err);
    }
  }

  function handleStderr() {
    emitReadyFunc(new Error('Received data on stderr: ' +
                            stderrBuffer.toString()));
  }

  child.stdout.on('data', function(chunk) {
    stdoutBuffer += chunk;

child_process

This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it.

ISC
Latest version published 8 years ago

Package Health Score

65 / 100
Full package analysis