[英]Getting output on frame instead of terminal (Perl-Tk)
#!/usr/local/bin/perl
use Tk;
# Main Window
$mw = new MainWindow;
$label = $mw -> Label(-text=>"Hello folks") -> pack();
$button = $mw -> Button(-text => "Click here to Flush rules",
-command =>\&flush) -> pack();
MainLoop;
sub flush {
$mw->messageBox(-message=>"Initiating flushing.. click on OK button");
system ("iptables -L");
system ("iptables -F");
system ("iptables -L");
}
我編寫了這段代碼,它的作用是當用戶單擊按鈕時會出現一個消息框
然后,當我單擊“確定”按鈕時,它會調用子程序flush
,然后 output 會顯示在終端上,如下所示:
我希望它出現在同一個消息框上。 我該怎么做?
我在 perlmonks 得到了這個問題的答案。
perlmonks 的帖子鏈接是-> http://www.perlmonks.org/index.pl?node_id=920414
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
# Main Window
my $mw = new MainWindow;
$mw->geometry('+100+100');
my $label = $mw -> Label(-text=>"Hello folks") -> pack();
my $button = $mw -> Button(-text => "Click here to Flush rules",
-command =>\&flush) -> pack();
MainLoop;
sub flush {
$mw->messageBox(-message=>"Initiating flushing.. click on OK button");
# the script hangs here, until the messagebox OK button is pressed.
my $text = $mw->Scrolled('Text')->pack();
#my $out1 = `iptables -L`;
my $out1 = `ls -la`;
$text->insert('end',"$out1\n");
$text->see('end');
#my $out2 = `iptables -F`;
my $out2 = `dir`;
$text->insert('end',"$out2\n");
$text->see('end');
#my $out3 = `iptables -L`;
my $out3 = `ps auxww`;
$text->insert('end',"$out3\n");
$text->see('end');
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.