Skip to main content

Process

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.

Load the module

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

Method reference

The Process module uses the following methods.

create

Defines a valid pathname to an executable file that you have permission to execute (or the user that started Moogfarmd has permissions to execute).

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

process

String

Yes

Path to an executable file (with permission).

Response

The method returns the following parameter.

Name

Type

Description

processObj

Object

An object containing the process to run.

arg

Defines the command line arguments required to run the process.

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

argString

Array of Strings

Yes

An array of of strings representing command line arguments required to run the process.

Response

None.

run

Takes the object returned by the create method and runs the process in a separate child process of Moogfarmd.

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

processObj

Object

Yes

The object returned by the create method.

Response

The method returns the following parameter.

Type

Description

Object

An object containing the process results.

runToExit

Takes the object returned by the create method, runs the process and returns when the process exits.

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

processObj

Object

Yes

The object returned by the create method.

Response

The method returns the following parameter.

Type

Description

Object

An object containing the process results.

terminate

Stops the process.

Request arguments

The method takes the following arguments.

Name

Type

Required

Description

processObj

Object

Yes

The object returned by the create method.

Response

None.

Example

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).