Process.spawnChildProcess()

Spawn a child process and have it run a command.

This method should only be used when low-level access to the raw child process instance is necessary. Instead, when possible, use `executeCommand()`-- it has a much easier and much less error-prone interface. This method, on the other hand, uses the `child_process.spawn()` method from Node.js core. The success exit from this machine will be called BEFORE the command has finished running (i.e. before the resulting child process exits). Note that it is _very important_ that this method is synchronous, to ensure that the child process instance returned is available in time to bind events.

Usage

Hover over inputs/exits for more info.

var Process = require('machinepack-process');


// Spawn a child process and have it run a command.

Process.spawnChildProcess({

command: 'ls',

cliArgs: [ '-la' ],

dir: '/Users/mikermcneil/foo',

environmentVars: {},

}).execSync();

Inputs

command required

The command to run in the child process, without any CLI arguments or options.

'ls'
cliArgs

An array of command-line arguments (e.g. `commit` or `install`) and/or options (e.g. `-al` or `-f 7` or `--foo='bar'`) to pass in.

[ '-la' ]
dir

The path to the directory where this command will be run.

'/Users/mikermcneil/foo'
environmentVars

A dictionary of environment variables to provide to the child process.

{}

Exits

error

An unexpected error occurred.

success

OK.

'==='