下面的代码:它成功地打开一个终端,但没有显示在输出为什么我不能从这个终端获得输入和输出?
try {
String command= "/usr/bin/xterm";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
BufferedWriter os =
new BufferedWriter(new OutputStreamWriter(pr.getOutputStream()));
BufferedReader is =
new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
while ((line = is.readLine()) != null) {
System.out.print(line);
}
} catch (Exception io) {
}
点#1值得自己单独upvote。每当我在生产代码中找到一个空白的try/catch时,我都不得不压制坚定的冲动。 – mcfinnigan
除了这些优点以外,还需要读取子进程的错误流 –
@Hemal:这在第三项中有所解释,我不认为这个特定项与手边的问题有关。 –