Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Running .jar file like a process in another program

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading