1

カスタム出力ストリームを使用して、実行可能ファイルからの出力を Jtext 領域に表示しようとしています。

実行可能ファイルはボタンから呼び出されます

        try {
            Process p = Runtime.getRuntime().exec("cgminer.exe" + " -o " + Infos.Address + ":" + Infos.Port + " -u " + Infos.User + " -p " + Infos.Password);
            p.waitFor();

            String line;

            BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
            while((line = error.readLine()) != null){
                System.out.println(line);
            }
            error.close();

            BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
            while((line=input.readLine()) != null){
                System.out.println(line);
            }

            input.close();

            OutputStream outputStream = p.getOutputStream();
            PrintStream printStream = new PrintStream(outputStream);
            printStream.println();
            printStream.flush();
            printStream.close();
        }
            catch (Exception e) {
                // ...
              }
    }

}

そして、出力はjtextに向けられます

public class CustomOutputStream extends OutputStream {
    private JTextArea textArea;

    public CustomOutputStream(JTextArea textArea) {
        this.textArea = textArea;
    }

    @Override
    public void write(int b) throws IOException {
        textArea.append(String.valueOf((char) b));
        textArea.setCaretPosition(textArea.getDocument().getLength());
    }
}

私の問題は、最初のクラスを呼び出すとボタンがロックされ、出力が jtext に出力されないことです。出力が表示されるのは、cgminer を強制終了したときだけです。

これは私の脳が歪んでいるので、どんな助けも本当に感謝しています。

4

1 に答える 1