General Scripting console

Simple Javascript Example

Console

function addIntegers(parm1, parm2) {
    return parm1 + parm2;
}
var sum = addIntegers(5, 8);
ms.log(sum);

Result

*** Script: 13

Example of calling into Java files on the MID Server

Console

// Import necessary Java classes
var File = Packages.java.io.File;

// Get the current directory
var currentDirectory = new File(".");

// Check if the directory is valid
if (!currentDirectory.isDirectory()) {
    ms.log("Current directory is not valid.");
} else {
    // List files in the directory ending with ".sh"
    ms.log("Generate a listing of the directory");
    var files = currentDirectory.list(function(file, name) {
        return name.endsWith(".sh");
    });

    // Print the filtered file names
    ms.log("Number of files: "+files.length.toString());
    if (files.length > 0) {
        ms.log("\n.sh Files:\n--"+ files.join("\n--"));
    } else {
        ms.log("No .sh files found in the current directory.");
    }
}

Result

*** Script: Generate a listing of the directory
*** Script: Number of files: 5
*** Script: 
.sh Files:
--installer.sh
--uninstall.sh
--configure.sh
--stop.sh
--start.sh

Last updated