I want to execute a command mspview -r "C:\\Users\\SS\\Desktop\\phantomjs-1.9.2-windows\\image.tif". How can I do it via Java code? I am trying to do this with a batch file. The same command when I run with the help of RUN. I am getting correct output. I have executed a .exe program with the help of a batch file with the following code C:\Users\SS\Desktop\phantomjs-1.9.2-windows\phantomjs.exe.
-
possible duplicate of How do I run a batch file from my Java Application?Jost– Jost2013-10-15 07:28:36 +00:00Commented Oct 15, 2013 at 7:28
-
@Jost I know how to execute a batch file from Java.I need to execute a command in cmd which need to produce same result as when it is run on RUNsethulekshmis– sethulekshmis2013-10-15 09:32:59 +00:00Commented Oct 15, 2013 at 9:32
Add a comment
|
2 Answers
You need to use ProcessBuilder
Process process = new ProcessBuilder(
"C:\\PathToExe\\exe.exe","param1","param2").start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:", Arrays.toString(args));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
code that is already found on stackoverflow Execute external program in java
1 Comment
sethulekshmis
I know this code and I can executing .exe.But the problem is that i want to start Microsoft Office Document Imaging which is to start OCR of an image.I can do this by executing the mspview -r "C:\\Users\\SS\\Desktop\\phantomjs-1.9.2-windows\\image.tif".But what i want pass the above command to RUN & executes it