0

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.

Jost
  • 1,549
  • 12
  • 18
  • possible duplicate of [How do I run a batch file from my Java Application?](http://stackoverflow.com/questions/615948/how-do-i-run-a-batch-file-from-my-java-application) – Jost Oct 15 '13 at 07: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 RUN – sethulekshmis Oct 15 '13 at 09:32

2 Answers2

1

You're basically asking how to run shell commands in java, right?

Runtime.getRuntime().exec("whatever system call you want");
yamafontes
  • 5,552
  • 1
  • 18
  • 18
0

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

Community
  • 1
  • 1
RamonBoza
  • 8,898
  • 6
  • 36
  • 48
  • 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 – sethulekshmis Oct 15 '13 at 09:28