Hi monks, I am here seeking for your wisdom. I am trying to develop a interface in perl-Tk of some old scripts I wrote before. One of the features I would like to have is to present in a text box, the log information of the called script while it is been executed. The problem I have is that when I call the script, the interface script waits until the called one finished to present its STDOUT, and I want this log to be showed while the script is been executed. To explain my self better, I wrote a simple test case composed by two files: test.pl and test3.pl. The first one have a textbox and a button, when the button is pressed, the second script is called and the log information is presented in the textbox. The second just grabs the STDIN and prints it back until the STDIN have a “aaa”chain.

test.pl

#!/usr/bin/perl -w use Tk; $main = MainWindow -> new(); $text_box = $main -> Scrolled ("Text",-spacing2=> 1, -spacing3 => 1, -scrollbars => "e", -height => 20, -background => "white", -relief => "ridge") +->pack(); $start = $main->Button()->pack(); $start-> configure (-text => "Start", -command => [\&count]); MainLoop(); sub count { open(README, "test3.pl |") or die "Can't run program: $!\n"; while(<README>) { $text_box -> insert ("end", $_); } close(README); }

test3.pl

#!/usr/bin/perl -w print “Write something: \n”; while (<>) { print; if ($_ =~ /aaa/){ exit; } }
Them the problem is that test.pl has to wait until test3.pl is finished, to show the log in the textbox. What I want is that the STDOUT of test3.pl is showed in the textbox while it is been executed. Thanks in advance for your help, and excuse me if it is silly question.

In reply to Processing STDOUT of a called perl script during execution by jcorso

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.