I am starting a separate process in my Java program using ProcessBuilder
This is were the process gets made:
Class klass=Program.class;
String[] output=new String[2];
String javaHome = System.getProperty("java.home");
String javaBin = javaHome +
File.separator + "bin" +
File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = klass.getCanonicalName();
ProcessBuilder builder = new ProcessBuilder(
javaBin, "-cp", classpath, className);
Process process = builder.start();
process.waitFor();
Program.class is the following:
public class Program {
public static void main(String[] args) {
System.out.println("Hi!");
}
I want the standard output to produce Hi!
, and the standard error, if I were to, for example, not add a semicolon after System.out.println("Hi!")
then the standard error would be:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert ";" to complete BlockStatements
at Program.main(Program.java:6)
So, how can I do this? Ideally, the program converts these into two strings.
Thanks