sulhome / spawn-manager

A node module to facilitate creating new sub processes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#spawn-manager module

This module contains the SpawnManager class and the spawnEvents enum. This module facilitates the management of creating sub processes using spawn.

API Documentation

Classes

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

Constants

spawnEvents : enum

Enum representing the events that will be fired by the SpawnManager.

Typedefs

cmdResultCallback : function

Callback to be called after the command finish executing.

result : Object

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

Kind: global class

new SpawnManager()

create new SpawnManager

spawnManager.runCommand(cli, cmdArguments, cmdDir, cb)

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;
});

spawnEvents : enum

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

cmdResultCallback : function

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

result : Object

Kind: global typedef
Properties

Name Type Description
stdoutVal string command stdout value
stderrVal string command stderr value
exitCode number command exit code

About

A node module to facilitate creating new sub processes

License:MIT License


Languages

Language:JavaScript 100.0%