in wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java [321:385]
public Streams executeCommand( String command, boolean ignoreStdErr, boolean ignoreNoneZeroExitCode )
throws CommandExecutionException
{
ChannelExec channel = null;
BufferedReader stdoutReader = null;
BufferedReader stderrReader = null;
Streams streams = null;
try
{
channel = (ChannelExec) session.openChannel( EXEC_CHANNEL );
fireSessionDebug( "Executing: " + command );
channel.setCommand( command + "\n" );
stdoutReader = new BufferedReader( new InputStreamReader( channel.getInputStream() ) );
stderrReader = new BufferedReader( new InputStreamReader( channel.getErrStream() ) );
channel.connect();
streams = CommandExecutorStreamProcessor.processStreams( stderrReader, stdoutReader );
stdoutReader.close();
stdoutReader = null;
stderrReader.close();
stderrReader = null;
int exitCode = channel.getExitStatus();
if ( streams.getErr().length() > 0 && !ignoreStdErr )
{
throw new CommandExecutionException( "Exit code: " + exitCode + " - " + streams.getErr() );
}
if ( exitCode != 0 && !ignoreNoneZeroExitCode )
{
throw new CommandExecutionException( "Exit code: " + exitCode + " - " + streams.getErr() );
}
return streams;
}
catch ( IOException e )
{
throw new CommandExecutionException( "Cannot execute remote command: " + command, e );
}
catch ( JSchException e )
{
throw new CommandExecutionException( "Cannot execute remote command: " + command, e );
}
finally
{
if ( streams != null )
{
fireSessionDebug( "Stdout results:" + streams.getOut() );
fireSessionDebug( "Stderr results:" + streams.getErr() );
}
IOUtil.close( stdoutReader );
IOUtil.close( stderrReader );
if ( channel != null )
{
channel.disconnect();
}
}
}