I want to write a java program A that runs another program B and prints the stack trace of B.
I know that I can print the stack trace of A with the below code
for( i = 0; i < Thread.currentThread().getStackTrace().length; i++ ) {
System.out.println(Thread.currentThread().getStackTrace()[i].
getMethodName());
}
But is it possible to print the stack trace of program B if i am executing it like this from A
Process pr = Runtime.getRuntime().exec("javac B.java");
pr.waitFor();
pr = Runtime.getRuntime().exec("java B").printStackTrace();
pr.waitFor();