Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Pipeing to a Tk-App

by schweini (Friar)
on Feb 17, 2003 at 04:54 UTC ( #235886=perlquestion: print w/replies, xml ) Need Help??

schweini has asked for the wisdom of the Perl Monks concerning the following question:

Hi there,
In this perl/Tk program i'm working on, i am opening a pipe to a simplistic, minimalistic "print-preview" Tk program:
open(VIRTUALPRN, "| perl");
... and some thime later i simply do some
print VIRTUALPRN "foobar\n"
but the "preview" program only pops up after i close VIRTUALPRN (something which i don't want to do), and my main program waits for the preview program to terminate before ending (something i don't want, either).
this is under WinXP, BTW.

Anybody know how i can make the previewer pop up immediatly after the open(), let my main program not wait for the previewer to exit, and make all of this DWIMANWIS (Do What I Mean, And Not What I Say)?

here's the previewer:
use Tk; $mw = MainWindow->new(-width => 300, -height => 600); $pp = $mw->Scrolled("Text")->pack; $pp->configure( -background => 'white', -scrollbars => 'osoe', -font => '*-courier-medium-r-*-*-17-*' ); tie(*PP, 'Tk::Text', $pp); sub foo { while($l = <STDIN>) { print INVOICEVIEW $l; $pp->update(); } } MainLoop();

Replies are listed 'Best First'.
Re: Pipeing to a Tk-App
by graff (Chancellor) on Feb 17, 2003 at 05:42 UTC
    After you do this:
    open(VIRTUALPRN, "| perl");
    ... and before you do this:
    print VIRTUALPRN "foobar\n"
    you could try this:
    select VIRTUALPRN; # make this the "default" output handle $|++; # disable output buffering on this handle
    Or, more elegantly:
    use FileHandle; ... my $VirtualPrnFH = new FileHandle; $VirtualPrnFH->open( "| perl" ); $VirtualPrnFH->autoflush(1); # turn off buffering ... print $VirtualPrnFH "foobar\n"; ...
    If you're only writing a small amount of content to that process, the default buffering would withhold output to the process until the file handle closes, which you could do explicitely in the parent process (rather than just exiting), but it's better to turn off buffering.
      that did the trick. i forgot to select VIRTUALPRN before doing the $|++.
      silly me.
      Thanks a lot!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://235886]
Approved by Paladin
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2020-06-01 00:36 GMT
Find Nodes?
    Voting Booth?
    If programming languages were movie genres, Perl would be:

    Results (177 votes). Check out past polls.