cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Snap To Call An EXE or BAT batch File On Another Server

andre_mangatal
New Contributor

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

5 REPLIES 5

cstewart
Former Employee

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.

Thanks a lot for your help cstewart!

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);
        }
    }
}

};

bilesh_ganguly
New Contributor II

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