public static String grabConsoleError(Runnable f) {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        PrintStream err = new PrintStream(buf);
        PrintStream err0 = System.err;

        System.setErr(err);
        try {
            f.run();
        } finally {
            System.setErr(err0);
        }
        err.flush();
        return buf.toString();
    }
Capture the console error during the execution of the provided function.
tools/src/test/java/org/apache/kafka/tools/ToolsTestUtils.java