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,

Heba A.
  • 127
  • 2
  • 15
  • Add "/C" to the command. See [this post](http://stackoverflow.com/questions/21295494/running-dos-command-line-from-c) fro reference. – MoMaj Mar 07 '17 at 06:15

1 Answers1

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();
Shamil
  • 910
  • 4
  • 17
  • 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? – Heba A. Sep 20 '16 at 09:02
  • 1
    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. – Shamil Sep 20 '16 at 15:14
  • 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. – Heba A. Sep 21 '16 at 09:25
  • **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. – Heba A. Sep 21 '16 at 10:34
  • **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. – Heba A. Sep 21 '16 at 11:53
  • my question now: Is there a way to force mirth run the exe as **console** not as background service ?? Here is a screenshot of the command line .. http://s15.postimg.org/7mn9608d7/mirth_java_notepad.png the first which has the PID = 8624 is the one by mirth .. I don't know if u can get what I mean ... How to force it to be changed to Console in the Session Name ? – Heba A. Sep 21 '16 at 15:47
  • My "notepad" is running as a console application, so I'm guessing that in your case Mirth is installed as a service, not as a standalone app. You may also try to create the *.bat file which you know is working and try smt like this: runtime.exec(["C:\\Temp\\test.bat"]); – Shamil Sep 21 '16 at 18:09
  • How can I make sure of that? .. I've already tried this option but unfortunately it didn't work. – Heba A. Sep 22 '16 at 09:30
  • You tried which option? Try both ways - installing Mirth as a standalone application and running as the service. In the latter case it might be that your service is not given a permission to launch external applications. – Shamil Sep 22 '16 at 15:16
  • sorry for misunderstanding. I meant I tried the option of creating *.bat file and didn't work from mirth. I uninstalled and re-installed mirth to make sure of that and the problem is still there. Thanks for ur help, u made me understand more about developing using mirth. I had to go to plan B now, but I still wanna understand why it's not executable through mirth. – Heba A. Sep 22 '16 at 16:43
  • You might install Mirth on Amazon EC2 and if it's still not working, you may give me the access to that box to check what's going wrong with this particular application. – Shamil Sep 22 '16 at 20:28