Created
April 11, 2023 11:10
-
-
Save ievgiienko/72bd80f78c3635c05ab841341f433985 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.nio.charset.StandardCharsets; | |
public class Main { | |
public static void main(String[] args) throws IOException { | |
System.out.println("Parent process!"); | |
String path = "/Users/ievgiienko/Downloads/Child1/target/Child1-1.0-SNAPSHOT.jar"; | |
ProcessBuilder processBuilder = new ProcessBuilder(); | |
processBuilder.redirectErrorStream(true); | |
processBuilder.inheritIO(); | |
processBuilder.directory(new File("/Users/ievgiienko/Downloads/Child1/target/")); | |
processBuilder.command("java", "-jar", | |
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5006", | |
path); | |
Process process = processBuilder.start(); | |
if (!process.isAlive()) { | |
process.destroy(); | |
System.out.println("Error 1"); | |
} else { | |
System.out.println("Success"); | |
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8)); | |
while (process.isAlive()) { | |
String s = reader.readLine(); | |
if (s != null) | |
System.out.println(s); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment