Index: cli/src/main/java/com/sun/enterprise/admin/cli/AsadminMain.java =================================================================== --- cli/src/main/java/com/sun/enterprise/admin/cli/AsadminMain.java (revision 47395) +++ cli/src/main/java/com/sun/enterprise/admin/cli/AsadminMain.java (working copy) @@ -117,8 +117,13 @@ public void publish(java.util.logging.LogRecord logRecord) { if (!isLoggable(logRecord)) return; - final PrintStream ps = (logRecord.getLevel() == Level.SEVERE) ? System.err : System.out; - ps.println(getFormatter().format(logRecord)); + Console c = System.console(); + if (c != null) { + c.writer().println(getFormatter().format(logRecord)); + } else { + final PrintStream ps = (logRecord.getLevel() == Level.SEVERE) ? System.err : System.out; + ps.println(getFormatter().format(logRecord)); + } } } @@ -310,7 +315,7 @@ try { CLIUtil.displayClosestMatch(command, CLIUtil.getAllCommands(habitat, po, env), - strings.get("ClosestMatchedLocalAndRemoteCommands")); + strings.get("ClosestMatchedLocalAndRemoteCommands"), logger); } catch (InvalidCommandException e) { // not a big deal if we cannot help } @@ -322,7 +327,7 @@ try { CLIUtil.displayClosestMatch(command, CLIUtil.getLocalCommands(habitat), - strings.get("ClosestMatchedLocalCommands")); + strings.get("ClosestMatchedLocalCommands"), logger); } catch (InvalidCommandException e) { logger.info( strings.get("InvalidRemoteCommand", command)); Index: cli/src/main/java/com/sun/enterprise/admin/cli/CLIUtil.java =================================================================== --- cli/src/main/java/com/sun/enterprise/admin/cli/CLIUtil.java (revision 47395) +++ cli/src/main/java/com/sun/enterprise/admin/cli/CLIUtil.java (working copy) @@ -47,6 +47,7 @@ import org.glassfish.api.admin.*; import com.sun.enterprise.admin.cli.remote.RemoteCommand; import com.sun.enterprise.universal.i18n.LocalStringsImpl; +import java.util.logging.Logger; /** * CLI Utility class @@ -102,7 +103,8 @@ * to the specified command. */ public static void displayClosestMatch(final String commandName, - String[] commands, final String msg) + String[] commands, final String msg, + final Logger logger) throws InvalidCommandException { try { // remove leading "*" and ending "*" chars @@ -133,12 +135,14 @@ getMatchedCommands(trimmedCommandName, commands); //".*"+trimmedCommandName+".*", commands); // don't want to display more than 50 commands + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); if (matchedCommands.length > 0 && matchedCommands.length < MAX_COMMANDS_TO_DISPLAY) { - System.out.println(msg != null ? msg : + pw.println(msg != null ? msg : strings.get("ClosestMatchedCommands")); for (String eachCommand : matchedCommands) - System.out.println(" " + eachCommand); + pw.println(" " + eachCommand); } else { // find the closest distance final String nearestString = StringEditDistance.findNearest( @@ -146,12 +150,14 @@ // don't display the string if the edit distance is too large if (StringEditDistance.editDistance( trimmedCommandName, nearestString) < 5) { - System.out.println(msg != null? msg : + pw.println(msg != null? msg : strings.get("ClosestMatchedCommands")); - System.out.println(" " + nearestString); + pw.println(" " + nearestString); } else throw new InvalidCommandException(commandName); } + pw.flush(); + logger.severe(sw.toString()); } catch (Exception e) { throw new InvalidCommandException(commandName); } Index: cli/src/main/java/com/sun/enterprise/admin/cli/MultimodeCommand.java =================================================================== --- cli/src/main/java/com/sun/enterprise/admin/cli/MultimodeCommand.java (revision 47395) +++ cli/src/main/java/com/sun/enterprise/admin/cli/MultimodeCommand.java (working copy) @@ -234,7 +234,7 @@ try { CLIUtil.displayClosestMatch(command, CLIUtil.getAllCommands(habitat, po, env), - strings.get("ClosestMatchedLocalAndRemoteCommands")); + strings.get("ClosestMatchedLocalAndRemoteCommands"), logger); } catch (InvalidCommandException e) { // not a big deal if we cannot help } @@ -245,7 +245,7 @@ try { CLIUtil.displayClosestMatch(command, CLIUtil.getLocalCommands(habitat), - strings.get("ClosestMatchedLocalCommands")); + strings.get("ClosestMatchedLocalCommands"), logger); } catch (InvalidCommandException e) { logger.info( strings.get("InvalidRemoteCommand", command));