Announcement

Collapse
No announcement yet.

Executing a batch file with Mirth Connect, batch file seems to get stuck

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

  • Executing a batch file with Mirth Connect, batch file seems to get stuck

    I have written a channel that creates a script file and a batch file that with export the entire Mirth Connect configuration (and hopefully email \ ftp it back to the home office). The issue I am having is that the batch file appears to get stuck. When I run the batch file manually, it processes in a few seconds, but through the channel, it looks like it get stuck, until I redeploy the channel. Here is my code:

    Code:
    //Login info for Mirth
    mirthPassword = xxxxxx ;
    mirthUser = xxxxxx ; 
    
    //where to put the backup, put the "/" at the end:
    var backupLocation = "c:/SIS_INTERFACES/Install Files/Backup/";
    
    //where mirth is located:
    var mirthDrive = "c:";
    var mirthLocation = "C:/SIS_INTERFACES/Mirth Connect/";
    
    //create the script file for the batch file to use
    var scriptFile = "exportcfg \""+backupLocation+"config_backup.xml\""
    FileUtil.write(backupLocation+"mirth_script.txt", false, scriptFile);
    
    logger.info("Createing Batch File")
    //create the batch file to do the backup
    var batchFile = ""
    +"cd "+mirthDrive+" \r\n"
    +"cd "+mirthLocation+" \r\n"
    +"java -jar mirth-cli-launcher.jar mirth-cli-launcher.xml -a https://127.0.0.1:8443 -u "+mirthUser
    +" -p "+mirthPassword+" -v 0.0.0 -s \""+backupLocation+"mirth_script.txt\" \r\n"
    +"quit";
    logger.info("Batch File Created");
    FileUtil.write(backupLocation+"backup_mirth.bat", false, batchFile);
    
    //wait a bit for things to settle down...
    java.lang.Thread.sleep(5000);
    
    //execute batch file
    logger.info("running batch file");
    
    var pr = java.lang.Runtime.getRuntime().exec(backupLocation+"backup_mirth.bat");
    pr.waitFor();
    
    logger.info("Batch File Ran");
    Any thought?

    Thanks,
    Joe

  • #2
    Assuming obviously that you're on a Windows machine using a DOS runtime from the JVM, you'll need a few changes to make that work:

    Code:
    //Login info for Mirth
    mirthPassword = xxxxxx ;
    mirthUser = xxxxxx ; 
    
    //where to put the backup, put the "/" at the end:
    var backupLocation = "c:/SIS_INTERFACES/Install Files/Backup/";
    
    //where mirth is located:
    var mirthDrive = "c:";
    var mirthLocation = "C:/SIS_INTERFACES/Mirth Connect/";
    
    //create the script file for the batch file to use
    var scriptFile = "exportcfg \""+backupLocation+"config_backup.xml\""
    FileUtil.write(backupLocation+"mirth_script.txt", false, scriptFile);
    
    logger.info("Createing Batch File")
    //create the batch file to do the backup
    var batchFile = ""
    +mirthDrive+" \r\n"
    +"cd "+mirthLocation+" \r\n"
    +"java -jar mirth-cli-launcher.jar mirth-cli-launcher.xml -a https://127.0.0.1:8443 -u "+mirthUser
    +" -p "+mirthPassword+" -v 0.0.0 -s \""+backupLocation+"mirth_script.txt\" \r\n"
    +"exit";
    logger.info("Batch File Created");
    FileUtil.write(backupLocation+"backup_mirth.bat", false, batchFile);
    
    //wait a bit for things to settle down...
    java.lang.Thread.sleep(5000);
    
    //execute batch file
    logger.info("running batch file");
    
    var pr = java.lang.Runtime.getRuntime().exec(backupLocation+"backup_mirth.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();
    
    logger.info("Batch File Ran");
    Last edited by narupley; 12-22-2012, 09:55 AM.
    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


    • #3
      This worked! Thanks!

      Comment

      Working...
      X