The Process module allows you to run and control the execution of another process. You can run a process in two ways:
Use the
run
method to run the process in a separate child process of Moogfarmd.Use the
runToExit
method to run the process and only return when the process exits.
Stop processes with the terminate
method. These methods are detailed below.
The Process module is available to load into any standard Moobot. To load it, define a new global variable at the top of the Moobot Javascript file. For example:
var proc = MooBot.loadModule('Process');
The Process module uses the following methods.
Defines a valid pathname to an executable file that you have permission to execute (or the user that started Moogfarmd has permissions to execute).
The method takes the following arguments.
Name | Type | Required | Description |
---|---|---|---|
| String | Yes | Path to an executable file (with permission). |
The method returns the following parameter.
Name | Type | Description |
---|---|---|
| Object | An object containing the process to run. |
Defines the command line arguments required to run the process.
The method takes the following arguments.
Name | Type | Required | Description |
---|---|---|---|
| Array of Strings | Yes | An array of of strings representing command line arguments required to run the process. |
None.
Takes the object returned by the create
method and runs the process in a separate child process of Moogfarmd.
The method takes the following arguments.
Name | Type | Required | Description |
---|---|---|---|
| Object | Yes | The object returned by the |
The method returns the following parameter.
Type | Description |
---|---|
Object | An object containing the process results. |
Takes the object returned by the create
method, runs the process and returns when the process exits.
The method takes the following arguments.
Name | Type | Required | Description |
---|---|---|---|
| Object | Yes | The object returned by the |
The method returns the following parameter.
Type | Description |
---|---|
Object | An object containing the process results. |
Stops the process.
The method takes the following arguments.
Name | Type | Required | Description |
---|---|---|---|
| Object | Yes | The object returned by the |
None.
The following function runs an external tool thisTool
using the Process module:
function runTool(thisTool,toolArgs,toExit)
{
var toolRun=proc.create(thisTool);
for ( var argIdx = 0; argIdx < toolArgs.length ; argIdx++)
{
toolRun.arg(toolArgs[argIdx]);
}
if ( toExit === true )
{
proc.runToExit(toolRun);
var toolResults=toolRun.output();
toolResults=toolResults.replace("\n","");
return(toolResults);
}
else
{
proc.run(toolRun);
return;
}
}
Usage:
var toolScript = "/usr/share/moogsoft/scripts/hip_chat.py";
var toolArgs = [ "--room=","Support Team", "--sigid=",sigId ];
var hipChatData = runTool( toolScript,toolArgs, true );
The above calls the tool runner, retrieves data, runs the process as "run to exit" (runToExit = true).