webMethods

webMethods

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
Expand all | Collapse all

Run a bat file from a java flow

  • 1.  Run a bat file from a java flow

    Posted Tue July 01, 2003 08:35 AM

    Hi all!

    Is there anyone out there who knows how you run a .bat file from an IS flow. I dont mind to code if thats neccasery.
    The task is to make a flow that runs a .bat file that maps a server when its called.

    Thanks.
    M


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 2.  RE: Run a bat file from a java flow

    Posted Tue July 01, 2003 12:03 PM

    Try writing a java service with the following code:

    try{
    Runtime.getRuntime().exec(“batchFileName.bat”);
    }catch(Exception e){}


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: Run a bat file from a java flow

    Posted Tue July 01, 2003 01:20 PM

    Thanks for your answers!

    I tryed the first example but I get a strange error.
    C:\IntegrationServer4\webMethods\IntegrationServer4\packages\Utils\code\source\runBatFile.java:36: illegal escape character
    Runtime.getRuntime().exec(“c:\map.bat”);
    ^
    1 error
    (The ^ sign is under the ; character)

    Do you have a qlue of what this means

    Michael


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: Run a bat file from a java flow

    Posted Tue July 01, 2003 01:29 PM

    Use / instead of ; or, even better, use java.io.File.separator


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 5.  RE: Run a bat file from a java flow

    Posted Wed July 02, 2003 05:59 AM

    Correct it as below:

    Runtime.getRuntime().exec(“c:\\map.bat”);

    (Note the two backward slashes.)

    But it is better to create the string using File.separator so that your code will be portable across different operating systems.

    Runtime.getRuntime().exec(“c:” + java.io.File.separator + “map.bat”);


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 6.  RE: Run a bat file from a java flow

    Posted Wed July 02, 2003 07:08 AM

    Hi all!

    I got it to work with

    try{
    Runtime.getRuntime().exec(“batchFileName.bat”);
    }catch(Exception e){}

    Thanks for all answers.

    Michael


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 7.  RE: Run a bat file from a java flow

    Posted Wed July 02, 2003 07:33 AM

    Michael,
    Your Java service would be more robust if it waited for the background process to finish and ensured that an int code of 0 was returned.
    You current java service will act the same way, regardless of whether or not your .bat file executed successfully.


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 8.  RE: Run a bat file from a java flow

    Posted Thu November 25, 2004 01:48 PM

    i need to execute a bat file with parameters
    does anyone knows how do i do that?
    thanks


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 9.  RE: Run a bat file from a java flow

    Posted Thu November 25, 2004 04:09 PM

    You can use fireCommandExec service found in WmSamples package. First call pub.string:messageFormat service and pass the value to pattern in serciceIn as “yourBatchfile.bat {0}” where 0 is the argument you want to pass. You can pass more than one argument by adding {1}, {2} as so forth. Then call fireCommandExec service and pass the final value to fullCommand you got from messageFormat.

    HTH


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 10.  RE: Run a bat file from a java flow

    Posted Thu November 25, 2004 04:54 PM