CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Readin STDOUT of external program through a pipe

 



xsustek
New User

Dec 2, 2010, 10:07 AM

Post #1 of 3 (441 views)
Readin STDOUT of external program through a pipe Can't Post

Hi,

I need to read a STDOUT of an external program in my perl script. The thing is that that program is running all the time and I need to react immediatelly after it outputs every line. What happens is that when the external program outputs a line, my script doesn't do anything because that line is somewhere buffered. I tried $|=1, but did not work.



This is the code:

Code
#!/usr/bin/perl 
open (IN,'monbro -N monitor_definition |' ) or die "Error";
$|=1;
while ($line = <IN>) {
print $line;
}
close IN;



I
the prob


(This post was edited by xsustek on Dec 2, 2010, 1:08 PM)


FishMonger
Veteran / Moderator

Dec 2, 2010, 1:47 PM

Post #2 of 3 (430 views)
Re: [xsustek] Readin STDOUT of external program through a pipe [In reply to] Can't Post

Take a look at these modules.

http://search.cpan.org/~toddr/IPC-Run-0.89/lib/IPC/Run.pm
http://search.cpan.org/~jesse/perl-5.12.2/ext/IPC-Open2/lib/IPC/Open2.pm
http://search.cpan.org/~jesse/perl-5.12.2/ext/IPC-Open3/lib/IPC/Open3.pm


rovf
Veteran

Dec 6, 2010, 1:58 AM

Post #3 of 3 (415 views)
Re: [xsustek] Readin STDOUT of external program through a pipe [In reply to] Can't Post

AFIK, *reading* from a handle is always unbuffered.

Of course you also need to make sure that the external program writes "non-buffered" to stdout.

Ronald

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives