Registre stdout y stderr desde el comando ssh en el mismo orden en que se creó

Version corta: ¿Es posible registrar el stdout y el stderr en el lado local de un comando ejecutado remotamente a través de ssh en el mismo orden en que se emitió en el host remoto? ¿Si es así, cómo?

Versión larga:

Estoy intentando registrar el resultado estándar y de error de un comando SSH ejecutado remotamente (usando Jsch) en el mismo orden en que fue emitido por el comando remoto. En otras palabras, si el comando remoto escribe "a" en stdout, luego "b" en stderr, luego "c" en stdout, quiero que el registro en el lado del cliente (local) lea:

a
b
c

A continuación se muestra lo que tengo hasta ahora. Se acerca relativamente a lo que quiero, pero creo que será evidente que no garantiza el orden de salida correcto en el lado del cliente.

public int exec(String strCommand) throws ExceptionUnableToExecCommand {
    JSch jsch = new JSch();
    Session session = null;
    ChannelExec channel = null;
    try {
          session = jsch.getSession(user, host, 22);
          UserInfo ui = new cyclOps.jsch.UserInfo(password);
          session.setUserInfo(ui);
          session.connect();
          channel = (ChannelExec) session.openChannel("exec");
          channel.setCommand(strCommand);
          channel.setInputStream(null);
          InputStream in = channel.getInputStream();
          InputStream err = channel.getErrStream();
          channel.connect();
          /* getOutput() defined below. */
          return this.getOutput(channel, in, err);
    } catch (JSchException | IOException e) {
        throw new ExceptionUnableToExecCommand("Unable to execute " + strCommand + " " + this.toString(), e);
    } finally {
        if (channel != null) channel.disconnect();
        if (session != null) session.disconnect();
    }
}

private int getOutput(ChannelExec channel, InputStream in, InputStream err) throws IOException { 
    byte[] tmp = new byte[1024];
    while(true){
        while(in.available() > 0){
            int i=in.read(tmp, 0, 1024);
            if(i<0)break;
            this.sshLogger.logOutputFromSSH(new String(tmp, 0, i));
        }
        while(err.available() > 0){
            int i=err.read(tmp, 0, 1024);
            if(i<0)break;
            this.sshLogger.logOutputFromSSH(new String(tmp, 0, i));
        }
        if(channel.isClosed()){
            return channel.getExitStatus();
        }
        try{Thread.sleep(1000);}catch(Exception ee){}
    }
}

Creo que debería señalar que esta es una versión modificada de Exec.java de los ejemplos del sitio web Jsch.

Respuestas a la pregunta(2)

Su respuesta a la pregunta