Re: [問題] thread+呼叫外部程式

看板java作者 (Terry)時間18年前 (2008/04/03 18:06), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/3 (看更多)
※ 引述《starskgb (Metal)》之銘言: : 當main裡有迴圈或等待輸入等情況時,叫出來的外部程式會block住,一定要等整隻程式 : 結束或按crl+c外部程式才會開始run,要怎麼讓程式跟外部程式都能跑呢??謝謝~~ : call外部程式的部分,無論放在main,while,thread裡都一樣,都會被block住@@ : code如下: : class th extends Thread { : public void run() : { : try { : Runtime t = Runtime.getRuntime(); : Process pr=t.exec(某執行檔); pr.waitFor(); //<----加這個看看 : } catch (IOException e) { } : } : } : class test { : public static void main(String args[]) throws Exception : { : th x = new th(); : x.start(); : while(true){ } //接收socket用 : } : } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.229.148.245

04/04 01:28, , 1F
不行耶@@ 它還是要等到按ctl+c才會跑
04/04 01:28, 1F
文章代碼(AID): #17zAmIYw (java)
文章代碼(AID): #17zAmIYw (java)