#!/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");
}
我制作了这段代码,它的作用是当用户点击按钮时出现一个消息框
然后当我点击OK按钮时,它调用子程序flush
,然后输出显示在终端上,如下所示:
我希望它出现在同一个消息框中。我该怎么办?
答案 0 :(得分:1)
答案 1 :(得分:0)
我在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');
}