Run a bat file from a java flow

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

Try writing a java service with the following code:

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

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

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

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”);

Hi all!

I got it to work with

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

Thanks for all answers.

Michael

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.

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

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

Done!
Thanks NN!!!