[J2SE] 如何讓exec() 可以繼續輸入/取得文字

看板java作者 (消失)時間14年前 (2009/11/22 12:27), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
想要去跑一個 xx.exe的檔案 請問要怎麼讓exec 持續的可以輸入輸出資訊呢? 以cmd的情況就是 1. C:\me.exe 2. sfjpoiawenoidsjv (要輸入的文字) 3. 取得output的文字 然後 Step 2,3 一直輪流 直到沒有東西輸入 也許有人會問說1,2可以和在一起,但是這個exe這樣和在一起下 就是沒有用 簡略程式碼如下: try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec("\"C:\\me.exe\""); InputStream stderr = proc.getErrorStream(); InputStreamReader isr = new InputStreamReader(stderr); BufferedReader br = new BufferedReader(isr); String line = null; System.out.println("<ERROR>1"); while ((line = br.readLine()) != null) System.out.println(line); System.out.println("</ERROR>2"); int exitVal = proc.waitFor(); System.out.println("Process exitValue: " + exitVal); } catch (Throwable t) { t.printStackTrace(); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.31.141

11/22 18:19, , 1F
不是有 getOutputStream 和 getInputStream ?
11/22 18:19, 1F

11/22 18:48, , 2F
getErrorStream()? ERROR?
11/22 18:48, 2F
文章代碼(AID): #1B2Bt0ES (java)