Moogsoft Docs

Process

Description

The Process module allows you to run and control the execution of another process.

The Process module is available to load into any standard MooBot.

To use, at the top of a MooBot js file, define a new global object proc to load the Process module:

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 moog_farmd, or runToExit run and only return when the process exits.

Stop processes running with terminate

These methods are detailed below.

Reference Guide

proc.create

proc.create()

Defines a valid pathname to an executable file that you have permission to execute (or the user that started moog_farmd 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

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

proc.run()

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

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

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

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[argsIdx]);
        }
        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).