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.
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) {
},
});
The command to run, including any whitespace-delimited CLI args/opts.
'ls -la'
The path to the directory where this command will be run.
'/Users/mikermcneil/foo'
A dictionary of environment variables to provide to the child process.
{}
The maximum number of miliseconds to wait for this command to finish.
60000
An unexpected error occurred.
The specified path points to a something which is not a directory (e.g. a file or shortcut).
Insufficient permissions to spawn process from the specified path (i.e. you might need to use `chown`/`chmod`)
Cannot run process from the specified path because no such directory exists.
The specified command was automatically killed because it had not finished before the configured time limit (`timeout`).
OK.
{ stdout: '...', stderr: '...' }