Получение вывода по кадру вместо терминала (Perl-Tk) - PullRequest
0 голосов
/ 12 августа 2011
#!/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");
}

Я сделал этот код и он делает то, что когда пользователь нажимает кнопку, появляется окно сообщения

enter image description here

Затем, когда я нажимаю кнопку OK, этовызывает подпрограмму flush и затем вывод выводится на терминал следующим образом:

enter image description here

Я хочу, чтобы он отображался в том же окне сообщения.Как я могу это сделать?

Ответы [ 2 ]

1 голос
/ 14 августа 2011

не использовать систему захват STDOUT / STDERR (qx, IPC :: System :: Simple, IPC :: Run ...) обновить метку (так же просто, как обновить $ textvariable ... см., Например, виджет демонстрационной программы Tk)
0 голосов
/ 17 августа 2011

Я получил ответ на этот вопрос в 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');
}
...