0

In mirth , in a JavaScript Writer Destination I am trying to run a .exe file with arguments \ as the following:

oShell.ShellExecute(commandtoRun,file_path,"","open","1"); 

and I get an error at this line:

var oShell = new ActiveXObject("Shell.Application"); 

the error is:

ReferenceError: "ActiveXObject" is not defined. 

I searched and learnt that my piece of code can only run on internet explorer , and actually I am writing this script to run in a middle-ware which is Mirth Connect

Can anyone help me using one of these options: - a way to run .exe fle with arguments in Mirth? - an alternative for ActiveXObject in Javascript? - a way to invoke ActiveXObject in Mirth?

Best Regards,

1
  • Add "/C" to the command. See this post fro reference. Commented Mar 7, 2017 at 6:15

1 Answer 1

1

Unless you have ActiveXObject Java object in your classpath this will not work. What you may use instead:

var runtime = new Packages.java.lang.Runtime.getRuntime(); runtime.exec(["notepad", "C:\\Temp\\test.txt"]); 

or

var processBuilder = new Packages.java.lang.ProcessBuilder("notepad", "C:\\Temp\\test.txt"); var process = processBuilder.start(); 
Sign up to request clarification or add additional context in comments.

11 Comments

Both pieces of code helped me in getting NO ERRORS , but when trying to run the code, there is actually nothing executed, the statements are interpreted and it interprets the following lines, but nothing runs. I have tried it on Mirth, Google chrome, and Internet explorer. Any hint about why I am having this problem?
You need to forget about Chrome and IE if you are developing for Mirth. Use Rhino JavaScript Debugger to debug your scripts instead. Second, both code snippets above use standard Java packages, so try run your application from standalone Java application. If that works then move that code to the Mirth script.
Your hints were useful. But, I'm having different problem now. The code works fine. When I give a path to a file that doesn't exist it gives me an exception that the file doesn't exist, and this is fine. But when I give path to an exe file which really exists, the code itself is executed with no problem at all , but the file itself isn't ! Does it needs to be forced or what ? I checked the file permissions as somebody suggested and they are ok ! It's the same for all files not for a specific file.
Update: In a standalone Java application , it runs only .exe installed by windows available in system variables and defined as known commands , but doesn't run any other exe. When I tried the same in Mirth , it doesn't execute any. When passing the full path of my exe file it runs the code but doesn't execute the file itself. And when tried with notepad, It gives me nothing on mirth , it doesn't run the code like when tried on a java application.
Update: using cmd through tasklist command, when trying to run notepad like the code above through mirth it ran as a process in the background, but notepad isn't actually opened or executed.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.