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.

2
  • possible duplicate of How do I run a batch file from my Java Application? Commented 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 RUN Commented Oct 15, 2013 at 9:32

2 Answers 2

1

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

Runtime.getRuntime().exec("whatever system call you want");
Sign up to request clarification or add additional context in comments.

Comments

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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.