@@ -87,9 +87,14 @@ public static String exec(final String commandWithArgs) throws IOException {
8787 }
8888
8989 public static String executeCommandAndGetOutput (final String commandWithoutArgs , final String [] args , final File directory ) throws IOException {
90+ return executeCommandAndGetOutput (commandWithoutArgs , args , directory , false );
91+ }
92+
93+ public static String executeCommandAndGetOutput (final String commandWithoutArgs , final String [] args , final File directory ,
94+ final boolean mergeErrorStream ) throws IOException {
9095 final CommandLine commandLine = new CommandLine (commandWithoutArgs );
9196 commandLine .addArguments (args );
92- return executeCommandAndGetOutput (commandLine , directory );
97+ return executeCommandAndGetOutput (commandLine , directory , mergeErrorStream );
9398 }
9499
95100 public static String executeCommandAndGetOutput (final String starter , final String switcher , final String commandWithArgs ,
@@ -101,16 +106,22 @@ public static String executeCommandAndGetOutput(final String starter, final Stri
101106 }
102107
103108 public static String executeCommandAndGetOutput (final CommandLine commandLine , final File directory ) throws IOException {
109+ return executeCommandAndGetOutput (commandLine , directory , false );
110+ }
111+
112+ public static String executeCommandAndGetOutput (final CommandLine commandLine , final File directory , final boolean mergeErrorStream ) throws IOException {
104113 final ByteArrayOutputStream out = new ByteArrayOutputStream ();
105- final ByteArrayOutputStream err = new ByteArrayOutputStream ();
114+ final ByteArrayOutputStream err = mergeErrorStream ? out : new ByteArrayOutputStream ();
106115 final PumpStreamHandler streamHandler = new PumpStreamHandler (out , err );
107116 final DefaultExecutor executor = new DefaultExecutor ();
108117 executor .setWorkingDirectory (directory );
109118 executor .setStreamHandler (streamHandler );
110119 executor .setExitValues (null );
111120 try {
112121 executor .execute (commandLine );
113- logger .log (Level .SEVERE , err .toString ());
122+ if (!mergeErrorStream ) {
123+ logger .log (Level .SEVERE , err .toString ());
124+ }
114125 return out .toString ();
115126 } catch (ExecuteException e ) {
116127 // swallow execute exception and return empty
0 commit comments