很抱歉,如果這是重復(fù)的,但沒有其他解決方案。我正在嘗試編寫一個(gè)Java應(yīng)用程序,該應(yīng)用程序?qū)⒄{(diào)用批處理文件,打印出該批處理文件在做什么,然后等待其完成執(zhí)行,然后再執(zhí)行其他任何操作。我已經(jīng)讀過,通過Process.getOutputStream()發(fā)送換行會(huì)觸發(fā)“按任意鍵繼續(xù)...”提示,但它對(duì)我而言并不是這樣做。這是我的test.bat:@echo offecho This is a test batch file.echo This text should be readable in the console windowecho Pausing...pauseecho done.exit這是我的Java驅(qū)動(dòng)程序:public class Tester { String cmd[] = { "cmd", "/c", "C:/Test Folder/test.bat" }; BufferedReader in = null; BufferedWriter out = null; Process p = null; 在while循環(huán)中,它將打印出:Starting process...Started process 2018699554INFO [2018699554] > This is a test batch file.INFO [2018699554] > This text should be readable in the console windowINFO [2018699554] > Pausing...而且永遠(yuǎn)不要傳遞暫停語句。我嘗試重定向錯(cuò)誤輸出,發(fā)送VK_ENTER并發(fā)送隨機(jī)密鑰全部無濟(jì)于事。有任何想法嗎?
1 回答

慕哥9229398
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超6個(gè)贊
使用緩沖的寫入器,您必須在實(shí)際寫入之前刷新緩沖區(qū)。在out.write()之后調(diào)用out.flush()。
添加回答
舉報(bào)
0/150
提交
取消