Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The run_cmd method is intended used to execute commands on the command prompt line from a script.

The run_cmd_timeout method is intended used to execute commands on the command prompt line with the specified process termination timeout.

When invoking commands, the command prompt line window does not open, i.e. the commands are executed in silent hidden mode.

The syntax for calling methods is as followsSyntax for method invocation:

Code Block
function run_cmd (cmd: String)
function run_cmd_timeout (cmd: String, timeout: int)

Method arguments:

  1. cmd is a command prompt for the command line.
  2. timeout  (only for run_cmd_timeout) is a timeout for process to terminate command line process termination timeout after the command execution.

Example 1. Run the curl utility and send a POST request with the text "Hello" to the test URL https://postman-echo.com/post

Code Block
var s = run_cmd("curl --request POST --url https://postman-echo.com/post --data \'Hello\'");
DebugLogString(s);

Example 2. Show Display the CPU usage on Graph Chart 1, updating information on Timer 3.

Code Block
var id = "1"; // id of the Charts object
var timer_id = "3"; // id of the Timer object to trigger the script
slave_id = "DESKTOP-5397BVV"; // id of the Computer object

if (Event.SourceType == "TIMER" && Event.Action == "TRIGGER" && Event.SourceId == timer_id)
{
	    var date = Event.GetParam("date");
	    var time = Event.GetParam("time");
	    var cpu = "for /f \"tokens=2* delims=^,\" %k in ('typeperf \"\\Processor Information(_Total)\\% Processor Time\" -sc 1 ^| findstr \":\"') do echo %k";
	    var cpu_usage = run_cmd(cpu);
	    var cpu_usage2 = cpu_usage.replace(/\"/g,"");
	    var cpu_usage3 = cpu_usage2.replace(/\s/g,"");
	    DebugLogString(cpu_usage3);
	    DoReactStr("ANALOGCHART",id,"ANALOG_PARAMS","int_obj_id<"+id+">,parent_id<>,slave_id<"+slave_id+">,objid<"+id+">,chan<5>,core_global<1>,text<"+cpu_usage3+">, min_val<0>,max_val<100>,sensor_id<cpu_usage>,time<"+time+">,date<"+date+">");
}

...