Parth Doshi
Parth Doshi

Reputation: 4208

How to run a batch file of an application that takes images as arguments in java

I have a batch file run.bat that requires many arguments for it to run. It is a part of an application named GeoMatch for which I have GeoMatch.exe present in the same folder as the .bat file.

In order to run the application, I need to run the batch file.

By using command prompt in Windows , I run the batch file as follows:

 C:\programs\test\GeoMatch_demo>GeoMatch -t template.jpg -1 10 -h 100 -s search1.
 jpg -m 0.7 -g 0.9

I get my desired output. However, when I try to run the same from my Java Application I am not getting the desired result.

My Java code:

   import java.io.*;
   import java.lang.*;

  public class BatchDemo
    { 
       public static void main(String args[]) throws IOException
      { 
        try{
         String cmd;

           try { 

         String[] command = { "cmd.exe", "/C", "Start", "C:\\programs\\test\\GeoMatch_demo\\run.bat","C:\\programs\test\\GeoMatch_demo\\Search1.jpg","C:\\programs\\test\\GeoMatch_demo\\template.jpg"};
           Runtime r = Runtime.getRuntime();
           Process p = r.exec(command);
           p.waitFor();

            } catch (Exception e) 
            {

            System.out.println("Execution error");} 
        }
      catch(Exception e)
       {
     e.printStackTrace();
      }
  }
}

Also to run this .bat file we require 3 DLL's to be present in the same folder as the .bat file. I have added those 3 DLL's in my Java Project but still I don't get the desired result.

can someone help me ?

Thanks in advance

Upvotes: 0

Views: 493

Answers (2)

Oleg Mihailenko
Oleg Mihailenko

Reputation: 91

Try to add the path C:\programs\test\GeoMatch_demo into PATH environment variable.

Upvotes: 1

Boris Strandjev
Boris Strandjev

Reputation: 46953

when you execute the bat file from the java code you do not change the current directory in the cmd, meaning that you are not actually in C:\\programs\\test\\GeoMatch_demo\\. So the exe file can not be found. If you refer to the exe file with absolute path in the batch file, the problem should go away.

Upvotes: 1

Related Questions