I have wrote an array sorting console program (you are putting array elements inside and the program shows you array after Arrays.sort() method). Then i have made .jar file with this program.
Now i am trying to run this array sorting program from another app using ProcessBuilder:
public static void main(String[] args) {
String filePath = "src/Lab1/ArrayCreatingAndSorting.jar";
ProcessBuilder processBuilder = new ProcessBuilder("java", filePath);
try {
Process process = processBuilder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
I don’t know why, but the output is just "Process finished with exit code 0", not array sorting program output. Can you help me with my problem please?
>Solution :
The output "Process finished with exit code 0" basically means that the process ran successfully. If you would like to access the process output, you might want to use getInputStream-method of Process (see here).
Documentation of Process may also be of help.