10-31-2018 08:59 AM
Good day Snaplogic Community,
I am trying to run a .BAT batch file or an EXE file on a different server but on the same network as out groundplex. Is there a Snap that I can use or another method of doing this in a pipeline?
Thank you very much in advance!
Best regards
Andre
10-31-2018 10:47 AM
On a Groundplex you should be able to use the Script Snap to execute a command line, and in that invoke any OS command. If the Operating system supports remote execution of commands, then you should be able to achieve your task.
10-31-2018 11:00 AM
Thanks a lot for your help cstewart!
10-31-2018 11:07 AM
Hi CStewart
Do you know the exact commands or can guide me to an online resource to execute a command line in javascript? I was trying to edit the default code in the script snap.
var impl = {
/*
* These variables (input, output, error, log) are defined by the
* ExecuteScript snap when evaluating this script.
*/
input : input,
output : output,
error : error,
log : log,
/**
* The "execute()" method is called once when the pipeline is started
* and allowed to process its inputs or just send data to its outputs.
*
* Exceptions are automatically caught and sent to the error view.
*/
execute : function () {
this.log.info("Executing Transform Script");
**var wshShell = new ActiveXObject("WScript.Shell");**
wshShell.Run(“D:\dir\user.bat”);
while (this.input.hasNext()) {
try{
// Read the next document, wrap it in a map and write out the wrapper
var doc = this.input.next();
var wrapper = new java.util.HashMap();
wrapper.put(“original”, doc);
this.output.write(doc, wrapper);
this.log.info(“Transform Script finished”);
}
catch(err) {
var wrapper = new java.util.HashMap();
wrapper.put("errorMsg", err);
this.log.error(err);
this.error.write(wrapper);
}
}
}
};
10-31-2018 01:53 PM
Hi Andre,
You can try re-purposing java code in the script.
The following resource might be helpful.
https://www.mkyong.com/java/how-to-execute-shell-command-from-java/
Regards
Bilesh