I am trying to invoke non linux command on linux using java code. The libraries required for that command are installed on my linux machine. Here is my java code which invokes the command using Runtime.getRuntime().exec();
The command reads the borcode from the image file and decodes it and shows the value on console.
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class demo {
public static void main(String args[]){
getcodes();
}
public void getCodes(){
try
{
Process p;
String command[]=new String[3];
command[0]="dmtxread ";
command[1]="-n ";
command[2]="/home/administrator/sandip/xyz.tif";
System.out.println("Command : "+command[0]+command[1]+command[2]);
p=Runtime.getRuntime().exec(command);
System.out.println(p.waitFor());
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
System.out.print("Decoded :- "+line);
}
}catch(IOException e1) {
e1.getMessage();
e1.printStackTrace();
}catch(InterruptedException e2) {
e2.getMessage();
e2.printStackTrace();
}
}
}
As when I run this java code on linux I get following exception
part of exception is as follows:
Command : dmtxread -n /home/administrator/sandip/xyz.tif java.io.IOException: Cannot run program "dmtxread ": java.io.IOException: error=2, No such file or directory at java.lang.ProcessBuilder.start(ProcessBuilder.java:475) at java.lang.Runtime.exec(Runtime.java:610) at java.lang.Runtime.exec(Runtime.java:483) at leadertechbarcode.TwoDBarCodeReadHelper.getCodes(TwoDBarCodeReadHelper.java:53)
Some times the program hangs afterinvoking the following code line p=Runtime.getRuntime.exec(Command)
when I copy the command printed by the code and runs it on terminal it runs properly.
Please tell me friends in this problem.
Is there any other way to invoke this command using java?
Thanks You!