Buggy code:
class CommandContextImpl implements CommandContext { private static final Logger log = Logger . getLogger ( CommandContext . class ) ; private final CliConfig config ; private final CommandRegistry cmdRegistry = new CommandRegistry ( ) ; private Console console ; private boolean terminate ; private String cmdLine ; private DefaultCallbackHandler parsedCmd = new DefaultCallbackHandler ( true ) ; private boolean domainMode ; private ModelControllerClient client ; private String defaultControllerHost ; private int defaultControllerPort ; private String controllerHost ; private int controllerPort = - 1 ; private String username ; private char [ ] password ; private SSLContext sslContext ; private CommandContextImpl . LazyDelagatingTrustManager trustManager ; private Map < String , Object > map = new HashMap < String , Object > ( ) ; private final OperationRequestAddress prefix = new DefaultOperationRequestAddress ( ) ; private final NodePathFormatter prefixFormatter = new DefaultPrefixFormatter ( ) ; private final OperationCandidatesProvider operationCandidatesProvider ; private final OperationRequestHandler operationHandler ; private BatchManager batchManager = new DefaultBatchManager ( ) ; private final CommandCompleter cmdCompleter ; private BufferedWriter outputTarget ; private List < CliEventListener > listeners = new ArrayList < CliEventListener > ( ) ; private int exitCode ; private File currentDir = new File ( "" ) ; private boolean resolveParameterValues ; CommandContextImpl ( ) throws CliInitializationException { } CommandContextImpl ( String username , char [ ] password ) throws CliInitializationException { } CommandContextImpl ( String defaultControllerHost , int defaultControllerPort , String username , char [ ] password , boolean initConsole ) throws CliInitializationException { } CommandContextImpl ( String defaultControllerHost , int defaultControllerPort , String username , char [ ] password , InputStream consoleInput , OutputStream consoleOutput ) throws CliInitializationException { } protected void initBasicConsole ( InputStream consoleInput , OutputStream consoleOutput ) throws CliInitializationException { } private void copyConfigSettingsToConsole ( InputStream consoleInput , OutputStream consoleOutput ) { if ( consoleInput != null ) Settings . getInstance ( ) . setInputStream ( consoleInput ) ; if ( consoleOutput != null ) <START_BUG> Settings . getInstance ( ) . setOutputStream ( consoleOutput ) ; <END_BUG> Settings . getInstance ( ) . setHistoryDisabled ( ( ! ( config . isHistoryEnabled ( ) ) ) ) ; Settings . getInstance ( ) . setHistoryFile ( new File ( config . getHistoryFileDir ( ) , config . getHistoryFileName ( ) ) ) ; Settings . getInstance ( ) . setHistorySize ( config . getHistoryMaxSize ( ) ) ; } private void initCommands ( ) { } public int getExitCode ( ) { } private void initSSLContext ( ) throws CliInitializationException { } @ Override public boolean isTerminated ( ) { } private StringBuilder lineBuffer ; @ Override public void handle ( String line ) throws CommandLineException { } public void handleSafe ( String line ) { } @ Override public String getArgumentsString ( ) { } @ Override public void terminateSession ( ) { } @ Override public void printLine ( String message ) { } protected void error ( String message ) { } private String readLine ( String prompt , boolean password , boolean disableHistory ) throws CommandLineException { } @ Override public void printColumns ( Collection < String > col ) { } @ Override public void set ( String key , Object value ) { } @ Override public Object get ( String key ) { } @ Override public Object remove ( String key ) { } @ Override public ModelControllerClient getModelControllerClient ( ) { } @ Override public CommandLineParser getCommandLineParser ( ) { } @ Override public OperationRequestAddress getCurrentNodePath ( ) { } @ Override public NodePathFormatter getNodePathFormatter ( ) { } @ Override public OperationCandidatesProvider getOperationCandidatesProvider ( ) { } @ Override public void connectController ( ) throws CommandLineException { } @ Override public void connectController ( String host , int port ) throws CommandLineException { } @ Override public void bindClient ( ModelControllerClient newClient ) { } private void initNewClient ( ModelControllerClient newClient , String host , int port ) { } @ Override public File getCurrentDir ( ) { } @ Override public void setCurrentDir ( File dir ) { } private boolean handleSSLFailure ( ) throws CommandLineException { } private static final String [ ] FINGERPRINT_ALGORITHMS = new String [ ] { "MD5" , "SHA1" } ; private Map < String , String > generateFingerprints ( final X509Certificate cert ) throws CommandLineException { } private String generateFingerPrint ( final String algorithm , final byte [ ] cert ) throws GeneralSecurityException { } private boolean tryConnection ( final ModelControllerClient client , String host , int port ) throws CommandLineException { } @ Override public void disconnectController ( ) { } @ Override public String getControllerHost ( ) { } @ Override public int getControllerPort ( ) { } @ Override public void clearScreen ( ) { } String promptConnectPart ; String getPrompt ( ) { } @ Override public CommandHistory getHistory ( ) { } @ Override public String getDefaultControllerHost ( ) { } @ Override public int getDefaultControllerPort ( ) { } private void resetArgs ( String cmdLine ) throws CommandFormatException { } @ Override public boolean isBatchMode ( ) { } @ Override public BatchManager getBatchManager ( ) { } @ Override public BatchedCommand toBatchedCommand ( String line ) throws CommandFormatException { } @ Override public ModelNode buildRequest ( String line ) throws CommandFormatException { } protected ModelNode buildRequest ( String line , boolean batchMode ) throws CommandFormatException { } @ Override public CommandLineCompleter getDefaultCommandCompleter ( ) { } @ Override public ParsedCommandLine getParsedCommandLine ( ) { } @ Override public boolean isDomainMode ( ) { } @ Override public void addEventListener ( CliEventListener listener ) { } @ Override public CliConfig getConfig ( ) { } protected void setOutputTarget ( String filePath ) { } protected void notifyListeners ( CliEvent event ) { } @ Override public void interact ( ) { } @ Override public boolean isResolveParameterValues ( ) { } @ Override public void setResolveParameterValues ( boolean resolve ) { }

Fix:
Settings . getInstance ( ) . setStdOut ( consoleOutput ) ;