Re: [問題] 同時丟很多程式, 但是要等它跑完....
※ 引述《jumpings (薑餅)》之銘言:
: 就是呢, 為了要加快速度, 我同時要丟很多個軟體一起跑,
: 我是用 & 丟到背景來完成的, 但是我程式要等這些軟體跑完,
: 才能去 parse output, 這樣程式要怎麼寫 ?
: 舉例來說, 我要執行A軟體三次, 但是輸入檔案不一樣, 如下 :
: system "A input1 &";
: system "A input2 &";
: system "A input3 &";
: 接著我要讀 output1, output2, output3, 但是如果我這時候寫 :
: read output1;
: read output2;
: read output3;
: 這時候 output 都還沒有出來, 所以會讀不到檔案, 有沒有什麼辦法
: 可以讓軟體丟到背景之後等待, 然後等跑完再繼續執行 ?
: 感謝大家的回覆....
本來有想過用pid 不過pid支援度只有在UNIX like的作業系統支援度才會比較好
(事實上我以前做過的實驗 在win32系統上沒有成功過 那是幾年前的事)
所以如果真的想丟多執行緒的話 就還是用多執行緒的模組試看看
psudocode大概是這樣
=====
use 5.010 ;
use threads ;
$th1 = threads->create(\&sendjob , input1) ;
$th2 = threads->create(\&sendjob , input2) ;
$th3 = threads->create(\&sendjob , input3) ;
$th1->join ;
$th2->join ;
$th3->join ;
read output1;
read output2;
read output3;
sub sendjob{
system "A $_[0]" ;
}
--
如果青春注定要向前跑
他媽的...那我的出口在那?
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.80.154.230
※ 編輯: abliou 來自: 111.80.154.230 (04/21 00:17)
討論串 (同標題文章)
Perl 近期熱門文章
PTT數位生活區 即時熱門文章