Hello All.

I have a program that automatically restarts itself atfer a certain amount of time.
I am doing this to test some things out. The program is wrapped in a jar.
I run the jar from terminal with
java -jar ProgramName.jar

It will run and will output all the "System.out.println" outputs in terminal

When the program restarts itself, It stops outputing on terminal. It runs fine and everything, I just want to see the output. How would I accomplish this.

this is my restarting code.

public void Restart() throws IOException {
        try {
            final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
            final File currentJar = new File(ProgramName.class.getProtectionDomain().getCodeSource().getLocation().toURI());

            /* is it a jar file? */
            if (!currentJar.getName().endsWith(".jar")) {

            /* Build command: java -jar application.jar */
            final ArrayList<String> command = new ArrayList<>();

            final ProcessBuilder builder = new ProcessBuilder(command);
        } catch (URISyntaxException ex) {
            Logger.getLogger(ProgramName.class.getName()).log(Level.SEVERE, null, ex);

Any help would be appreciated.

Edited 1 Year Ago by scheppy

Have you tried redirecting the new process's output stream? There are various options for that (see the API doc). This one looks particularly interesting...

public ProcessBuilder inheritIO()
Sets the source and destination for subprocess standard I/O to be the same as those of the current Java process.

Edited 1 Year Ago by JamesCherrill


public ProcessBuilder inheritIO() was the perfect solution!!!!! :)

This question has already been answered. Start a new discussion instead.