执行命令的Java程序赢得';我不能继续

执行命令的Java程序赢得';我不能继续,java,Java,我试图让我的绘图仪在java中工作。 我有一个开始,但我不知道如何继续。 这就是我所拥有的: public static void main(String[] args) { try { Runtime runTime = Runtime.getRuntime(); Process process = runTime.exec("chiplotle"); BufferedReader in = new

我试图让我的绘图仪在java中工作。 我有一个开始,但我不知道如何继续。 这就是我所拥有的:

public static void main(String[] args) {

        try {
            Runtime runTime = Runtime.getRuntime();

            Process process = runTime.exec("chiplotle");


            BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));

            String line = null;

            System.out.println("this prints fine");


            while ((line = in.readLine()) != null) {
                System.out.println(line);
            }


            System.out.println("it never reaches this...");

        }
        catch (IOException e) {
            e.printStackTrace();
        }

    }
这是控制台中的输出:

我自己打字。但它和它没有任何关系。 而且它从不打印:

System.out.println("it never reaches this...");
看来我的程序被暂停输入了,对吗? 我怎样才能走得更远呢

  • 您应该在bagground线程中读取InputStream
  • 您需要获取进程的OutputStream,然后对其进行写入

    您不仅需要打印,还需要分析InputStream发送给您的文本,以决定何时通过PrintWriter向流程回写。

    我想在尝试读取其他行时,它被阻止了。谢谢。我认为这应该有助于我继续下去!
    OutputStream os = process.getOutputStream();
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
    PrintWriter pw = new PrintWriter(bw);
    
    // now you can write to the Process, i.e., pw.println("11");