推 starskgb:不行耶@@ 它還是要等到按ctl+c才會跑 04/04 01:28
※ 引述《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