Moogsoft Docs

Process

Description

The Process module allows you to run and control the execution of another process. It is available to load into any standard Moobot.

To use it, define a new global object at the top of a Moobot JavaScript file to load the module. For example:

var proc = MooBot.loadModule('Process');

Create a new process with create and access methods to run the process with arg.

Then run the process in one of two ways - either run in a separate child process of Moogfarmd, or runToExit run and only return when the process exits.

Stop processes running with terminate.

These methods are detailed below.

Reference Guide
proc.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 Argument

Name

Type

Description

process 

String

A pathname to an executable file (with permission).

Return Parameter

Name

Type

Description

processObj 

Object

An object containing the process to run.

proc.arg

Access a series of methods by passing strings representing command line arguments required to run the process.

Request Arguments

Name

Type

Description

argString 

Strings

A list of strings representing command line arguments required to run the process.

Return Parameter

Void - no value returned.

proc.run

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

Request Argument

Name

Type

Description

processObj 

Object

The object returned from the create method.

Return Parameter

Type

Description

Object

An object containing the process results.

proc.runToExit

Takes the object returned from create, runs the process and only returns when the process exits.

Request Argument

Name

Type

Description

processObj 

Object

The object returned from the create method.

Return Parameter

Type

Description

Object

An object containing the process results.

proc.terminate

Stops the created processes running (causes the process under the process object returned from create to be terminated).

Request Argument

Name

Type

Description

processObj 

Object

The object returned from the create method

Return Parameter

Void - no value returned.

Example

The following function runs an external tool toolName using the Process module:

function runTool(toolname,toolArgs,toExit) 
{
var toolRun=proc.create(toolName);
    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 );

This calls the tool runner, gets data back, runs the process as 'run to exit' (runToExit = true).