Re: [問題] 關於system
經由版友reizarc建議
下面是我寫的程式,外部會執行的程式為 a.c 編譯成 a.out
程式還是會像 利用$aa=`cmd`;print $aa; 的方式一樣,
a.out執行完畢才會印出變數 $aa
可以請問還有什麼地方有問題嗎?
run.pl
----------
use Tk;
$mw = MainWindow->new;
$bt = $mw->Button(-text => 'Clink to start', -command => \&Run);
$bt->pack(-fill => 'x');
$tx = $mw->Text(-width => 50, -height => 50);
$tx->pack;
MainLoop;
sub Run {
$bt->configure(-text => 'Running',-state=>'disabled');
open $fd, "./a.out |";
$mw->fileevent($fd, 'readable' => sub{
sysread $fd, $buf, 30;
$aa=$buf;
$tx->insert('end', $buf);
print $aa;
$done='Done';
if($aa =~/$done/ ){
close $fd;
undef $fd;
print "Done!!";
$bt->configure(-text => 'Clink to start ping',
-command => \&RunPing,
-state => 'normal');
}
});
}
a.c
-----
#include<stdio.h>
int main()
{
int i,j;
for(i=0;i<10;i++)
{
printf("a %d Hello World\n",i);
}
for(i=0;i<10;i++)
{
if(i%2==0)
for(j=0;j<2000000000;j++)
;
printf("b %d Hello World\n",i);
}
printf("Done\n");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.114.203.128
→
10/18 14:41, , 1F
10/18 14:41, 1F
→
10/18 14:43, , 2F
10/18 14:43, 2F
→
10/18 15:52, , 3F
10/18 15:52, 3F
→
10/18 20:24, , 4F
10/18 20:24, 4F
→
10/19 00:53, , 5F
10/19 00:53, 5F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
0
2
Perl 近期熱門文章
PTT數位生活區 即時熱門文章