-3

I need a piece of code that can invoke another java application and send two strings as parameters. And then get String (This is a JSON string) response.

process = new ProcessBuilder("XYZ", Address , Type).start(); 

In this statement I don't understand what XYZ means, and how to define a particular method of Java Application to be called through this ProcessBuilder statement.

Nathan Hughes
  • 94,330
  • 19
  • 181
  • 276
Ali khan
  • 1
  • 3
  • `ProcessBuilder`'s [javadoc](http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html#ProcessBuilder%28java.lang.String...%29) states this constructor's arguments are the program and parameters you want to execute. – Xavi López May 20 '15 at 14:43

1 Answers1

0

If you want to invoke another Java program (let's say it's called programName with arguments programArg1, programArg2), you'll probably have to use something along the lines of:

ProcessBuilder processBuilder = new ProcessBuilder("java", "programName", programArg1, programArg2);
Process process = processBuilder.start();
p.waitFor(); // If you need to wait until it finishes execution

Take a look at for instance this question to see how to read the program's output (in case it writes it through System.out): How to redirect Process Builder's output to a string?

Community
  • 1
  • 1
Xavi López
  • 27,550
  • 11
  • 97
  • 161