Announcement

Collapse
No announcement yet.

Is it possible to call external windows programs from inside a Mirth channel?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to call external windows programs from inside a Mirth channel?

    Is it possible to call external windows programs from inside a Mirth channel (Mirth version 2.2.1.5861)?
    I have created some AutoIT scripts compiled as *.exe I would like to launch from a Mirth channel for some external file management. Tried to call my scripts but do get Mirth errors or nothing happens, so I tried to call easy DOS commands like xcopy but got the same Mirth behavior. Please can somebody give my the right syntax for calling external windows programs from a Mirth channel?

  • #2
    http://stackoverflow.com/questions/1...-js-on-windows

    Comment


    • #3
      Yes it certainly is. There are already examples on these forums if you had done a search first:

      http://www.mirthcorp.com/community/f...ead.php?t=8125
      http://www.mirthcorp.com/community/f...ead.php?t=8504
      http://www.mirthcorp.com/community/f...ead.php?t=4443
      http://www.mirthcorp.com/community/f...ead.php?t=4297
      http://www.mirthcorp.com/community/f...ead.php?t=2529
      http://www.mirthcorp.com/community/f...read.php?t=310
      http://www.mirthcorp.com/community/f...ead.php?t=5306

      Basically you want to call this to execute a command and get a Process object:

      Code:
      var pr = java.lang.Runtime.getRuntime().exec(command);
      Then make sure to fully read both the input stream (actually the output from the process) and the error stream. Finally, call pr.waitFor() to ensure the process terminates correctly. Look at the Javadoc for more info: http://docs.oracle.com/javase/7/docs...g/Process.html. Also, you may want to check out ProcessBuilder as well.
      Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

      Nicholas Rupley
      Work: 949-237-6069
      Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


      - How do I foo?
      - You just bar.

      Comment


      • #4
        Thank you very much for your response, I will try your suggestions.

        Comment


        • #5
          Hi, checked and tried your suggestions exactly like described from:

          http://www.mirthcorp.com/community/f...ead.php?t=5306
          http://www.mirthcorp.com/community/f...read.php?t=310
          http://www.mirthcorp.com/community/f...ead.php?t=2529
          http://www.mirthcorp.com/community/f...ead.php?t=4443
          http://www.mirthcorp.com/community/f...ead.php?t=8125
          http://www.mirthcorp.com/community/f...ead.php?t=8504

          But no one of the code samples did work, every time I get the following error:

          ERROR ... [9ae2c3d4-eb4b-4ebe-9fc4-28a4b781d437_source_connector._fileEndpoint#167691 3011.receiver.1] org.mule.impl.DefaultComponentExceptionStrategy: Caught exception in Exception Strategy for: 9ae2c3d4-eb4b-4ebe-9fc4-28a4b781d437: org.mule.umo.routing.RoutingException: Failed to route event via endpoint: null. Message payload is of type: com.mirth.connect.model.MessageObject
          org.mule.umo.routing.RoutingException: Failed to route event via endpoint: null.

          Please can you send me an working Mirth channel code sample or Mirth channel XML-file for an easy command job like "C:\Windows\System32\cmd.exe /c copy /B c:\Test\test.txt c:\Test\test3.txt" called as external program from inside a Mirth transformer ?
          Or is my Mirth version 2.2.1.5861 not able to do this ?

          Thanks in Advance, Dorothea

          Comment


          • #6
            Hi Guys,

            no answer ? Are you on the point when you are at your wit's end ?
            I'll open a new thread and perhaps find the right people for the real information I need ...

            Comment


            • #7
              How to call external windows programs from inside a Mirth channel ?

              Hi,

              tried to call external windows programs from inside a Mirth channel (Mirth version 2.2.1.5861) like described in:

              http://www.mirthcorp.com/community/f...ead.php?t=5306
              http://www.mirthcorp.com/community/f...read.php?t=310
              http://www.mirthcorp.com/community/f...ead.php?t=2529
              http://www.mirthcorp.com/community/f...ead.php?t=4443
              http://www.mirthcorp.com/community/f...ead.php?t=8125
              http://www.mirthcorp.com/community/f...ead.php?t=8504

              But no one of the code samples did work, every time I get the following error:

              ERROR ... [9ae2c3d4-eb4b-4ebe-9fc4-28a4b781d437_source_connector._fileEndpoint#167691 3011.receiver.1] org.mule.impl.DefaultComponentExceptionStrategy: Caught exception in Exception Strategy for: 9ae2c3d4-eb4b-4ebe-9fc4-28a4b781d437: org.mule.umo.routing.RoutingException: Failed to route event via endpoint: null. Message payload is of type: com.mirth.connect.model.MessageObject
              org.mule.umo.routing.RoutingException: Failed to route event via endpoint: null.

              Please can you send me an working Mirth channel code sample or Mirth channel XML-file for an easy command job like "C:\Windows\System32\cmd.exe /c copy /B c:\Test\test.txt c:\Test\test3.txt" called as external program from inside a Mirth transformer ?
              Or is my Mirth version 2.2.1.5861 not able to do this ?

              Thanks in Advance, Dorothea

              Comment


              • #8
                If you post your channel, or at least the code you're using, it will be easier to troubleshoot. You will generally get more informative answers by doing that, rather than asking people to create entire channels from scratch for you.
                Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

                Nicholas Rupley
                Work: 949-237-6069
                Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


                - How do I foo?
                - You just bar.

                Comment


                • #9
                  For example, tried the following code from inside a working channel to copy a file from c:\Test\test.txt to c:\Test\test3.txt as test for calling external DOS commands:

                  java.lang.Runtime.getRuntime().exec("C:\\Windows\\ System32\\cmd.exe /c copy /B c:\Test\test.txt c:\Test\test3.txt");
                  java.lang.Runtime.getRuntime().exec("C:\\Windows\\ System32\\cmd.exe /c copy /B c:\\Test\\test.txt c:\\Test\\test3.txt");
                  java.lang.Runtime.getRuntime().exec("C:\\Windows\\ System32\\cmd.exe /c copy /B c:\Test\test.txt c:\Test\test3.txt >> test.log 1>&2");
                  java.lang.Runtime.getRuntime().exec("C:\\Windows\\ System32\\cmd.exe /c copy /B c:\\Test\\test.txt c:\\Test\\test3.txt >> test.log 1>&2");

                  Also tried the following code from inside a working channel to launch a batch file:

                  java.lang.Runtime.getRuntime().exec("c:/sendDirectory.bat");

                  var pr = java.lang.Runtime.getRuntime().exec("c:/sendDirectory.bat");
                  $gc('is',pr.getInputStream());
                  var thread = new java.lang.Thread(new java.lang.Runnable({run:function(){while($gc('is') .read()!=-1);}}));
                  thread.start();
                  while(pr.getErrorStream().read() != -1);
                  thread.join();
                  pr.waitFor();

                  But no one of the code samples did work, every time I get the following error:

                  ERROR ... [9ae2c3d4-eb4b-4ebe-9fc4-28a4b781d437_source_connector._fileEndpoint#167691 3011.receiver.1] org.mule.impl.DefaultComponentExceptionStrategy: Caught exception in Exception Strategy for: 9ae2c3d4-eb4b-4ebe-9fc4-28a4b781d437: org.mule.umo.routing.RoutingException: Failed to route event via endpoint: null. Message payload is of type: com.mirth.connect.model.MessageObject
                  org.mule.umo.routing.RoutingException: Failed to route event via endpoint: null.

                  Please can you give me a working Mirth channel code sample or Mirth channel XML-file for an easy command job like "C:\Windows\System32\cmd.exe /c copy /B c:\Test\test.txt c:\Test\test3.txt" called as external program from inside a Mirth transformer and calling an external batch file ?
                  Or is my Mirth version 2.2.1.5861 not able to do this ?

                  Thanks in Advance, Dorothea

                  Comment


                  • #10
                    The following worked perfectly fine for me on Windows:

                    Code:
                    var pr = java.lang.Runtime.getRuntime().exec('C:\\Windows\\System32\\cmd.exe /C copy /B C:\\temp\\test.txt C:\\temp\\test2.txt');
                    var thread = new java.lang.Thread(new java.lang.Runnable({run:function(){while(pr.getInputStream().read()!=-1);}}));
                    thread.start();
                    while (pr.getErrorStream().read() != -1);
                    thread.join();
                    pr.waitFor();
                    Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

                    Nicholas Rupley
                    Work: 949-237-6069
                    Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


                    - How do I foo?
                    - You just bar.

                    Comment


                    • #11
                      Hi Narupley,

                      this code really does the job (copy a file), thanks a lot. But beside it gives still an destination error:

                      ERROR-300: Transformer error
                      ERROR MESSAGE: Error evaluating transformer
                      com.mirth.connect.model.converters.SerializerExcep tion: org.xml.sax.SAXParseException; Premature end of file.
                      at com.mirth.connect.model.converters.DelimitedSerial izer.fromXML(DelimitedSerializer.java:54) .....

                      Have attached the used channel, please can you check why it gives still this error (Mirth version 2.2.1.5861).

                      Best Regards
                      Dorothea
                      Attached Files

                      Comment


                      • #12
                        You're probably reading in a blank file or something, that's why the serializer is complaining.
                        Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

                        Nicholas Rupley
                        Work: 949-237-6069
                        Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


                        - How do I foo?
                        - You just bar.

                        Comment


                        • #13
                          No, the test file "test.txt" I use is not blank, it contains plain text. Tried with large, medium, small and emty files and also with other file types, but everytime the same error:
                          ERROR-300: Transformer error
                          ERROR MESSAGE: Error evaluating transformer
                          com.mirth.connect.model.converters.SerializerExcep tion: org.xml.sax.SAXParseException; Premature end of file.
                          at com.mirth.connect.model.converters.DelimitedSerial izer.fromXML(DelimitedSerializer.java:54) .....

                          If we can not avoid the error, is it possible to switch off this error to get the log free of this unwanted error messages ?

                          Thanks and Best Regards
                          Dorothea

                          Comment


                          • #14
                            I do not mean the test.txt file you're using in your transformer (inside Runtime.exec()). I mean whatever file you're reading into the channel itself using the File Reader.
                            Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

                            Nicholas Rupley
                            Work: 949-237-6069
                            Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


                            - How do I foo?
                            - You just bar.

                            Comment


                            • #15
                              Originally posted by narupley View Post
                              I do not mean the test.txt file you're using in your transformer (inside Runtime.exec()). I mean whatever file you're reading into the channel itself using the File Reader.
                              Thank you very much, this was the cause of the error, I'm happy :-)
                              Best Regards
                              Dorothea

                              Comment

                              Working...
                              X