#spawn-manager module
This module contains the SpawnManager class and the spawnEvents enum. This module facilitates the management of creating sub processes using spawn.
- SpawnManager
This class abstracts the way you interact with spawn functionality in node by providing events which you can optionally listen to or you can just get the result of executing your command. Check return details of runCommand method
- spawnEvents :
enum
Enum representing the events that will be fired by the SpawnManager.
- cmdResultCallback :
function
Callback to be called after the command finish executing.
- result :
Object
This class abstracts the way you interact with spawn functionality in node by providing events which you can optionally listen to or you can just get the result of executing your command. Check return details of runCommand method
Kind: global class
create new SpawnManager
execute a new command in a sub process (spawn). This class implements EventEmitter and fire certain events while executing the command. Please review spawnEvents for the list of emitted events
Kind: instance method of SpawnManager
Param | Type | Description |
---|---|---|
cli | string |
the command name |
cmdArguments | Array |
command arguments |
cmdDir | string |
path to where the command will be executed. Pass null if you don't want to set it |
cb | cmdResultCallback |
callback function to be called after the command finish executing |
Example
let manager = new SpawnManager();
let cmdOutput = '';
let exitCode;
manager.runCommand('ping', ['-c','4','localhost'], null, (err, result) => {
// you can get the command exit code, stdout and stderr here in the result object
exitCode = result.exitCode;
});
manager.on(SpawnManager.spawnEvents.stdoutChunk, (text) => {
// you may want to subscribe to these events if you want to output the progress of a long running command for example but these subscription remains optional because you will get everything back in the result object
cmdOutput += text;
});
Enum representing the events that will be fired by the SpawnManager.
Kind: global constant
Read only: true
Properties
Name | Type | Default | Description |
---|---|---|---|
stdoutChunk | string |
"stdoutChunk" |
stdoutChunk represents a chunk of data returns from the command stdout |
stderrChunk | string |
"stderrChunk" |
stderrChunk represents a chunk of data returns from the command stderr |
error | string |
"cmdError" |
error represents an error occurred while executing the command |
Callback to be called after the command finish executing.
Kind: global typedef
Param | Type | Description |
---|---|---|
error | * |
An object repenting an error. |
the | result |
result of executing the command |
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
stdoutVal | string |
command stdout value |
stderrVal | string |
command stderr value |
exitCode | number |
command exit code |