Note that the following program does not work with Sun's JDK 1.0.2 on
Solaris, although it does work with the JDK 1.1 version.  On 1.0.2, it
failed with an IOException while reading from the child process.


import java.io.*;

class ProcessKiller {

    public static void main(String[] args) {
	if (args.length < 2)
	    error("usage: ProcessKiller kill_string command [args]");

	try {
	    String[] cmdArgs = new String[args.length - 1];
	    System.arraycopy(args, 1, cmdArgs, 0, cmdArgs.length);

	    Process child = Runtime.getRuntime().exec(cmdArgs);

	    LineInputStream lineIn =	// from Exercise 11.2
		new LineInputStream(child.getInputStream());

	    while (true) {
		String line = lineIn.readLine();
		System.out.println(line);
		if (line.indexOf(args[0]) != -1) {
		    child.destroy();
		    break;
		}
	    }
	} catch (EOFException ignore) {
	} catch (IOException e) {
	    error("I/O Exception: " + e);
	}
    }

    public static void error(String err) {
	System.err.println("ProcessKiller: " + err);
	System.exit(1); // non-zero argument means "not good"
    }
}
