Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: Re: Re: Handling program output in real time

by dvergin (Monsignor)
on Nov 10, 2003 at 07:37 UTC ( #305816=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Re: Handling program output in real time
in thread Handling program output in real time

I have stared very hard at the docs for IO::Pty and I can't dope out how to use it here. No doubt this is in part because I don't understand what is meant by: "the creation of a pseudo tty". (The topic is outside my normal field of Perl endeavors.)

Can you show how IO::Pty could be used to modify the second program in the OP (the program with PIPE1 in it) so that it would process the output from blackbox.pl in real time (leaving blackbox.pl untouched)?

Regarding the "system dependent" issue, I am running Linux 7.3 with the 2.4.20-20.7 kernel. I gather from the docs for IO::Tty that I sould be okay in that respect.


Comment on Re: Re: Re: Re: Handling program output in real time
Re: Re: Re: Re: Re: Handling program output in real time
by Anonymous Monk on Nov 10, 2003 at 08:25 UTC

    Not pretty, and perhaps there are better ways, but this may get you started anyway:

    #!/usr/bin/perl -w use strict; use IO::Pty; my $pty = new IO::Pty; my $slave = $pty->slave(); my $pid = fork(); die "Couldn't fork: $!" unless defined $pid; if($pid){ # dup STDOUT to Pty and run external program: $pty->close_slave(); open(STDOUT, ">&",$pty)||die $!; system "perl blackbox.pl"; print "\cD"; # send ^d to end } else { # this is your monitoring process $pty->make_slave_controlling_terminal(); print "*$_" while <$slave>; exit; } __END__

    Works for me on Linux.

Re: Re: Re: Re: Re: Handling program output in real time
by etcshadow (Priest) on Nov 10, 2003 at 16:15 UTC
    There's also a snippet here that does this.

    ------------
    :Wq
    Not an editor command: Wq

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://305816]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2014-09-23 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (212 votes), past polls