所以我有這樣的代碼:執行命令的過程
String[] command = new String[] { "java", "-jar", file.getName() };
try {
System.out.println("Loading input/output");
final Process process = Runtime.getRuntime().exec(command);
BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
final OutputStreamWriter out = new OutputStreamWriter(process.getOutputStream());
final BufferedReader consolein = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Loaded input/output");
new Thread() {
@Override
public void run() {
while (true) {
System.out.println("hi");
try {
String temp = consolein.readLine();
out.write(temp);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}.start();
while (true) {
System.out.println(in.readLine());
}
} catch (IOException e) {
e.printStackTrace();
}
,我試圖執行命令的運行罐子。輸入很好,我看到控制檯中的所有消息。我添加了「hi」消息來測試它是否工作。無論什麼時候我輸入什麼都會顯示但是,無論我輸入什麼內容都不會被髮送到正在運行的程序。我在這裏做錯了什麼?
你有沒有嘗試添加一個新行輸入的結束? – MadProgrammer
正如\ n?或者是什麼? – PaulBGD