Well, you often have read or heard that the medini JS scripting engine is not bound to a sand box as much as a browser engine is so you are able to execute external programs or read and write files to the file system, which gives you potential to script great stuff.
One common use case is to execute an external program and capture its output that the program usually writes to the console (standard output). In the attached version of helper.js you will find a new function with this signature:
/**
* @param cmd {Array} an array of command line arguments
* @param max {Number} maximum number of lines to read from the process output (default is 1000)
* @returns {Array} an array of output lines, never undefined or null
*/
function performCommand(cmd, max)
An example call looks like this:
load(".lib/helper.js");
var output = performCommand([ "cmd", "/?"], 1000);
console.log("CMD help text: {0}", output.join("\n"));
While this use case concentrates more on the output, there are other use cases where the executed program itself creates files or other stuff, so the calling script is more interested in the exit code of the program to know whether it succeeded or not. An example for such a program is the external tool curl.exe which is a neat little helper to retrieve content via various protocols like HTTP, FTP etc. from a server. Find a small library attached named curl.js that shows how you can execute curl.exe slightly different and returning the exit code instead of the output. Sample call may look like this:
var curl = load(".lib/curl.js");
/**
* Main script to test the library.
*/
function main() {
var temp = curl.newTemp("data", ".html");
var exit = curl.GET("http://www.google.de", temp);
console.log("Completed with {0}", exit);
console.log("Data written to {0}", temp);
}
// using a main function has the advantage to use "return"
main();Note that the curl.js expects the curl.exe co-located to really work. Anyway, its more a blueprint and should give you the ability to apply the same pattern to your script. Feel free to copy it and adapt it to your needs.
Happy Scripting
Jan