I am using Runtime.getRuntime().exec(test.class) to create a process and launch a test.class file.
test.class:
public class test {
public static void main(String[] args) {
doReturn();
}
public static String doReturn() {
System.out.println("printed output");
return "returned output";
}
}
in the Java application launching this process, I’d like to retrieve the output of this test.class
The code I use looks like:
Process proc = null;
String[] cmd = { "java", "test"};
proc = Runtime.getRuntime().exec(cmd);
InputStream inputStream = proc.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String line;
while ((line = bufferedReader.readLine()) != null)
{
System.out.println(line);
}
This snippet of code does not work: nothing is printed and I get an Exitvalue of 1 for my process.
=> How should I modify it (and / or modify test.class) to return “printed output” to my java application?
=> Is it possible to return “returned output” as well?
(I am new to Java so could you please be very detailed in your answers! Thx!)
I don’t know what are you want to do but try to remove the .class