【问题标题】:perl tk gui to show script stdout and stderr in text widgetperl tk gui 在文本小部件中显示脚本标准输出和标准错误
【发布时间】:2014-06-29 07:07:12
【问题描述】:

我有一个从命令按钮运行脚本的 GUI,但我怎样才能让它在文本小部件中显示输出?

如果我想通过日志文件插入显示输出,我可以将命令放在与运行按钮相同的按钮/子上吗?

use warnings;
use strict;
use Tk;
use Tk::Text ;
use POSIX 'strftime';
my $DATE = strftime("Report.pl for %dth %b %Y" , localtime());
my $mw = MainWindow->new;
my $filename = "c:\\Temp\\perl.txt";

$mw->geometry("720x500");
$mw->title("   backupadmin  ");

my $main_frame = $mw->Frame()->pack(-side => 'top', -fill => 'x');

my $left_frame = $main_frame->Frame(-background => "snow2")->pack(-side => 'left', -fill => 'y');
my $right_frame = $main_frame->Scrolled("Text", -scrollbars => 'se',-background => "black",-foreground => "yellow",-height => '44')->pack(-expand => 1, -fill => 'both');


my $failures_button = $left_frame->Button(-text => "  $DATE ",
                                -command => [\&runscript])->pack;
my $Close_button = $left_frame->Button(-text => '                       Close                       ',
-command => [$mw => 'destroy'])->pack;  
my $Help_button = $left_frame->Button(-text => "                  Help Guide                   ",
                                -command => [\&load_file])->pack(-side => "bottom");


my $Close_help = $left_frame->Button(-text => '                  Close Help                      ',
-command => [$right_frame => \&clear_file])->pack(-side => "bottom");                                   


MainLoop;
sub runscript {
  system("report.pl");

}

sub load_file {
  open (FH, "$filename");
  while (<FH>) { $right_frame->insert("end", $_); }
  close (FH);
}

sub clear_file {
    $right_frame->('quit');
}

【问题讨论】:

  • 在英语中,I 总是大写的。每个句子的第一个单词也是如此。您不需要&lt;code&gt; 标签。在将散文发布到此处之前,您可能应该通过拼写/语法检查器检查您的散文。
  • 问题不清楚。这个话题可能有帮助? stackoverflow.com/questions/2461472/…

标签: perl


【解决方案1】:

如果您的 report.pl 脚本输出到 STDOUT,那么您可以在 runscript 回调中尝试这样的操作:

sub runscript {
  right_frame->delete('1.0','end');
  my $text = `report.pl`;
  $right_frame->insert('end', $text);
}

或者,如果 report.pl 输出到 c:\temp\perl.txt,那么您可以尝试以下操作:

sub runscript {
  right_frame->delete('1.0','end');
  system("report.pl");
  load_file();
}

【讨论】:

    猜你喜欢
    • 2013-11-27
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多