Как сопоставить System.out и System.in с элементами управления SWT

Я работаю над инструментом для подключения к удаленному серверу с помощью jcraft.JSch (ssh на сервер Unix), возвращаю вывод и отображаю его вывод. Сценарий отлично работает, когда входы и выходы канала равны System.in и System.out. Но когда я пытаюсь использовать элементы управления SWT, он не может

  1. отображать точный результат, который я получаю с помощью System.out
  2. чтение из SWT Text управление эмуляцией System.in

    public void create() {
    
    dialogShell = new Shell(dialogShell, SWT.PRIMARY_MODAL | SWT.SHEET | SWT.RESIZE);
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 2;
    dialogShell.setLayout(gridLayout);
    final Text logText = new Text(dialogShell, SWT.MULTI | SWT.BORDER| SWT.READ_ONLY);
    GridData gridData0 = new GridData(GridData.FILL,GridData.FILL, true, true);
    gridData0.horizontalSpan = 2;
    logText.setLayoutData(gridData0);
    
    origOutPS = System.out;
    origErrPS = System.err;
    
    
    final Text cmdText = new Text(dialogShell, SWT.BORDER | SWT.V_SCROLL);
    final Button RunButton = new Button(dialogShell, SWT.PUSH);
    GridData gridDatal = new GridData(GridData.BEGINNING, GridData.FILL_HORIZONTAL, true,false);
    GridData gridData2 = new GridData(GridData.END, GridData.CENTER, false,false);
    cmdText.setLayoutData(gridDatal);
    RunButton.setLayoutData(gridData2);
    RunButton.setText("Execute");
    RunButton.addSelectionListener(new runButton(dialogShell,cmdText));
    
    dialogShell.setDefaultButton(RunButton);
    dialogShell.setSize(550, 250);
    dialogShell.setText("Processing....");
    
    OutputStream out = new OutputStream() {
        public void write(int b) throws IOException {
            logText.append(String.valueOf((char) b));
        }
    
        public void write(byte[] b,int off, int len) {
            logText.append(new String(b, off, len));
        }
    };
    PrintStream ps = new PrintStream(out,true);
    System.out.println("Passing the control!");
    System.setOut(ps);
    System.setErr(ps);
    
    
    InputStream in = new InputStream() {
        @Override
        public int read() throws IOException {
            String str = cmdText.getText();
            int pos = 0;
            //test if the available input has reached its end
            //and the EOS should be returned 
            if( str != null && pos == str.length()){
                str =null;
                //this is supposed to return -1 on "end of stream"
                //but I'm having a hard time locating the constant
                return java.io.StreamTokenizer.TT_EOF;
            }
            //no input available, block until more is available because that's
            //the behavior specified in the Javadocs
            while (str == null || pos >= str.length()) {
                try {
                    //according to the docs read() should block until new input is available
                    synchronized (this) {
                        this.wait();
                    }
                } catch (InterruptedException ex) {
                    ex.printStackTrace();
                }
            }
            //read an additional character, return it and increment the index
            return str.charAt(pos++);
        }
    };
    System.setIn(in);
    
    dialogShell.addListener(SWT.Close, new closelistener());
    
    //dialogShell.addShellListener(new MyshellAdapter(logText,cmdText,RunButton));
    dialogShell.open();
    }
    

Выше приведен диалог, и это результат, который я получаю

введите здесь описание изображения

тогда как, когда я подключаю вход канала к System.in и System.out, вывод выглядит следующим образом

введите здесь описание изображения


person Nauduri Venkata Ravi Rama Sast    schedule 14.08.2015    source источник