Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSCH通道外壳,输入/输出_Java_Shell_Netbeans_Jsch - Fatal编程技术网

Java JSCH通道外壳,输入/输出

Java JSCH通道外壳,输入/输出,java,shell,netbeans,jsch,Java,Shell,Netbeans,Jsch,我在使用JSCH和向shell发送命令时遇到了一些问题 我有一个控制台GUI窗口设置和system.out已重定向到TextArea,这工作正常,但我无法输入任何命令 以下是会话的连接代码 this.channel=session.openChannel("shell"); PipedInputStream pip = new PipedInputStream(40); this.channel.setInputStream(pip); PipedOutput

我在使用JSCH和向shell发送命令时遇到了一些问题

我有一个控制台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命令并显示输出,但是如果我现在想运行更多命令,这些命令就不起作用了

我有一个文本框设置和一个“发送”按钮将这些命令发送到下面编码的服务器

    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) {
    }

但是,点击“发送”按钮没有任何作用。我显然遗漏了一些简单的东西

我发现我需要将PrintStream声明为私有

 private PrintStream print;
然后在我创建了最初的PrintStream之后

 print = new PrintStream(pop); 
我能够在程序的其他部分访问它,而不是创建新的部分,因此最终我在send命令中所需要的只是

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