2013-10-21 50 views
0

我有一些使用JSCH和發送命令到shell的問題。JSCH通道外殼,輸入/輸出

我有一個控制檯GUI窗口的設置和System.out的已重定向到TextArea和這工作得很好,但我無法輸入任何命令

下面是會議

this.channel=session.openChannel("shell"); 

    PipedInputStream pip = new PipedInputStream(40); 
    this.channel.setInputStream(pip); 

    PipedOutputStream pop = new PipedOutputStream(pip); 
    PrintStream print = new PrintStream(pop); 

    this.channel.setOutputStream(System.out); 

    print.println("ls"); 

    this.channel.connect(3*1000); 
的連接代碼

這工作正常,並運行ls命令並顯示輸出,但是如果我現在想運行更多的命令這些不工作。

我有一個TextBox設置和一個「發送」按鈕,將這些命令發送到下面編碼的服務器。

String send = jServerInput.getText(); 

    try { 
     PipedInputStream pip = new PipedInputStream(40); 
     //this.channel.setInputStream(pip); 

     PipedOutputStream pop = new PipedOutputStream(pip); 
     PrintStream print = new PrintStream(pop); 
     //this.channel.setOutputStream(System.out); 
     //System.out.println(send); 
     print.println(send); 
    } catch (IOException iOException) { 
    } 

但是點擊「發送」按鈕什麼也不做。我清楚地失去了一些東西簡單

回答

1

我發現,我需要聲明的PrintStream作爲一家民營所以

private PrintStream print; 

然後我就創建初始的PrintStream爲

print = new PrintStream(pop); 

後我能訪問它在程序的其他部分而不是創建新的,所以我最終需要在我的發送命令中是

String send = jServerInput.getText(); 
print.println(send);