Process.executeCommand()

Execute a command like you would on the terminal.

This uses the `child_process.exec()` method from Node.js core to run the specified command. The success exit from this machine will not be called until the command has finished running (i.e. the resulting child process exits). If you need a more advanced/flexible interface, check out `spawnChildProcess()`. It is much lower-level, and exposes raw access to the child process instance.

Usage

Hover over inputs/exits for more info.

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


// Execute a command like you would on the terminal.

Process.executeCommand({

command: 'ls -la',

dir: '/Users/mikermcneil/foo',

environmentVars: {},

timeout: 60000,

}).exec({

// An unexpected error occurred.

error: function (err) {

 

},

// The specified path points to a something which is not a directory (e.g. a file or shortcut).

notADir: function () {

 

},

// Insufficient permissions to spawn process from the specified path (i.e. you might need to use `chown`/`chmod`)

forbidden: function () {

 

},

// Cannot run process from the specified path because no such directory exists.

noSuchDir: function () {

 

},

// The specified command was automatically killed because it had not finished before the configured time limit (`timeout`).

timedOut: function () {

 

},

// OK.

success: function (bufferedOutput) {

 

},

});

Inputs

command required

The command to run, including any whitespace-delimited CLI args/opts.

'ls -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.

{}
timeout

The maximum number of miliseconds to wait for this command to finish.

60000

Exits

error

An unexpected error occurred.

notADir

The specified path points to a something which is not a directory (e.g. a file or shortcut).

forbidden

Insufficient permissions to spawn process from the specified path (i.e. you might need to use `chown`/`chmod`)

noSuchDir

Cannot run process from the specified path because no such directory exists.

timedOut

The specified command was automatically killed because it had not finished before the configured time limit (`timeout`).

success

OK.

{ stdout: '...', stderr: '...' }