Search code examples
javaexecsift

Call exe file from java code


I am trying to use the colosift detector provided here: colorDescriptor. I am actually try to call the executable colorDescriptror.exe file from java. I am already run it with bat file and I want just to call the exe from my java code. My code is the following:

Process process = new ProcessBuilder("colorDescriptor.exe", "image.jpg", " --detector densesampling  ","  --ds_spacing 6", " --ds_scales 1.2 ","  --descriptor opponentsift ", " --output out.descr").start();

InputStream is = (InputStream) process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;

The executable is seems to run, but I am getting a error from colorsift code: Warning: no output file to write to. Thus, I am wondering which is the right way to parse my arguments in the executable here.

WORKING COMMAND:

colorDescriptor image.jpg --detector densesampling --ds_spacing 6 --ds_scales 1.2 --descriptor opponentsift   --output out.descr

Solution

  • Split the argument pairs into separate arguments without leading and trailing whitespace. For example:

    " --detector densesampling  "
    

    should be:

    "--detector", "densesampling"
    

    Make the same changes for the other argument pairs. Otherwise, an argument pair as in the posted code will be sent to the underlying program as a single argument, which the program will not recognize.