This is an old revision of the document!
Running an Executable from a Script
In MIStudio you can use the CommmandExecutor to run an external executable or script (.sh or .bat). In a script you can use the Java Runtime and create a Process to run a command.
Simple Example with One Parameter
var Runtime = Java.type("java.lang.Runtime"); var Process = Java.type("java.lang.Process"); //This runs the external program //Consider running this in its own Thread try { // Command to create an external process command = "notepad"; // Running the above command run = Runtime.getRuntime(); proc = run.exec(command); //will launch notepad.exe on windows } catch (e) { print("error in script: \n"+e.stack); } output="finished";
Example with a Command Array
In this example we need to run a CMD shell to launch a PDF viewer. This will run the default viewer on the system using Windows start.
var Runtime = Java.type("java.lang.Runtime"); var Process = Java.type("java.lang.Process"); pdfname="C:/Reports/SummaryReport_2023-01-24_12-58-26.pdf"; //launch pdf viewer using Windows START command = ["cmd.exe","/c","start",pdfname]; try { print("command for launching pdf viewer: "+command); rt = Runtime.getRuntime(); proc = rt.exec(command); } catch (e) { print("error in script: \n"+e.stack); } incomingValue;