import java.io.BufferedInputStream;
import java.io.IOException;
public class JavaExec {
	public static void main(String args[]) {
		Process p = null;
		System.out.println("creating child");
		Runtime rt = Runtime.getRuntime();
		String command[] = new String[2];
		command[0] = "java";
		command[1] = "Child";
		try {
			p = rt.exec(command);
		} catch (IOException ioe) {
			System.out.println("IOException occured");
		}
		try {
			p.waitFor();
		} catch (InterruptedException ie) {
			System.out.println("InterruptedException occured");
		}
		System.out.println("child has finished execution");
		BufferedInputStream pOut = new BufferedInputStream(p.getInputStream());
		byte output[] = null;
		try {
			output = new byte[pOut.available()];
			pOut.read(output);
		} catch (IOException ioe) {
			System.out.println("IOException occured");
		}
		System.out.println("output of the child process was: "
				+ new String(output));
	}
}