scriptexamplerunexecutable

This is an old revision of the document!


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.

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";

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;
  • scriptexamplerunexecutable.1674591755.txt.gz
  • Last modified: 2023/01/24 14:22
  • by wikiadmin