Moogsoft Docs

Process

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, define a new global object proc at the top of a Moobot JavaScript file:

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

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

Then run the process in one of two ways:

  • Use the run method to run in a separate child process of Moogfarmd.
  • Use the runToExit method to run and only return when the process exits.

Stop the processes with the terminate method. These methods are detailed below.

Reference Guide

You can use the following methods with the Process Moobot module.

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

Type Description
Object An object containing the process to run.

arg

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

Request Argument

Name Type Description
argString Strings A list of strings representing command line arguments required to run the process.

Return Parameter

None.

run

Takes the object returned from the create method 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.

runToExit

Takes the object returned from the create method, 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.

terminate

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

Request Argument

Name Type Description
processObj
Object The object returned from the create method.

Return Parameter

None.

Examples

The following function runs an external tool toolName using the Process Moobot 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).