作者Lordaeron (Terry)
站内java
标题Re: [问题] thread+呼叫外部程式
时间Thu Apr 3 18:06:09 2008
※ 引述《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
1F:推 starskgb:不行耶@@ 它还是要等到按ctl+c才会跑 04/04 01:28