2013-10-21 49 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);