private void run(final CommandShellImpl commandProcessor, String[] args, final InputStream in, final PrintStream out, final PrintStream err) throws Exception {
TerminalFactory terminalFactory = new TerminalFactory();
Terminal terminal = terminalFactory.getTerminal();
Console console = createConsole(commandProcessor, in, out, err, terminal);
CommandSession session = console.getSession();
session.put("USER", user);
session.put("APPLICATION", application);
session.put("LINES", Integer.toString(terminal.getTerminalHeight()));
session.put("COLUMNS", Integer.toString(terminal.getTerminalWidth()));
session.put(".jline.terminal", terminal);
session.put(NameScoping.MULTI_SCOPE_MODE_KEY, Boolean.toString(isMultiScopeMode()));
if (args.length > 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < args.length; i++) {
if (i > 0) {
sb.append(" ");
}
sb.append(args[i]);
}
try {
session.execute(sb);
} catch (Throwable t) {
if (t instanceof CommandException) {
session.getConsole().println(((CommandException) t).getNiceHelp());
} else {
session.getConsole().print(Ansi.ansi().fg(Ansi.Color.RED).toString());
t.printStackTrace(session.getConsole());
session.getConsole().print(Ansi.ansi().fg(Ansi.Color.DEFAULT).toString());
}
}
} else {
console.run();
}