Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can't get output from pipe with autoflush on

Reply
Thread Tools

Can't get output from pipe with autoflush on

 
 
Ishmael
Guest
Posts: n/a
 
      01-18-2007
Howdy,

I'm trying to get a list of clients/users on my network using 'rusers'.
When I run 'rusers' from the command line, the behavior is as follows:
First, it instantaneously prints list of clients/users (perfect) THEN
it hangs for several seconds (I think this is due to a problem with the
client database configuration, over which I have no control). In any
case, I would like to time out the function after a second or so, keep
the first chunk of output, and kill the 'rusers' function.
Unfortunately, it seems as if the output does not become accessible via
the filehandle (see below) unless 'rusers' exits normally (which takes
too long). I've tried turning 'autoflush' on, but this doesn't seem to
work.

Any help would be greatly appreciated! Here's the code:

undef $/; # Try eliminating OUTPUT_RECORD_SEPARATOR

print "Getting user list via rusers\n";
my ($pid, $rusers_out, @tmp);
eval {
local $SIG{ALRM} = sub { die "alarm clock restart\n" };
alarm $rusers_timeout;
eval {

$pid = open F, "rusers -a |" or die "rusers gave error: $!";
F->autoflush(1);
$rusers_out = <F>;

};
alarm 0;
if ($@) {
if ($@ =~ /alarm clock restart/) {
die "'rusers' timed out.\n"; # Create an exception to get out of
outer loop.
}
else {
die($@);
}
}
};
alarm 0;

if ( $@ ne '' ) {
print "$@";

# kill PID with a TERM (terminate) signal. Note: Control-C (INT
signal) also works.
my $num_successfully_killed = kill('TERM', $pid);

if ($num_successfully_killed != 1) {
print "Error: Could not kill rusers after timeout\n";
}
}

print "RUSERS OUTPUT: $rusers_out\n"; # Nothing gets here
exit;

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      01-19-2007
"Ishmael" <(E-Mail Removed)> wrote:
> Howdy,
>
> I'm trying to get a list of clients/users on my network using 'rusers'.
> When I run 'rusers' from the command line, the behavior is as follows:
> First, it instantaneously prints list of clients/users (perfect) THEN
> it hangs for several seconds (I think this is due to a problem with the
> client database configuration, over which I have no control). In any
> case, I would like to time out the function after a second or so, keep
> the first chunk of output, and kill the 'rusers' function.
> Unfortunately, it seems as if the output does not become accessible via
> the filehandle (see below) unless 'rusers' exits normally (which takes
> too long). I've tried turning 'autoflush' on, but this doesn't seem to
> work.


You need to get rusers to turn on *its* autoflush. If you trick it into
thinking it is talking to a terminal rather than program, it might do so.
I think the Expect module can arrange this trickery for you.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
 
 
 
Ishmael
Guest
Posts: n/a
 
      01-21-2007
Thanks for the help! The Expect module is fantastic!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[named pipe] i wanna know about validate of pipe handle of client lee, wonsun C++ 1 11-02-2004 04:29 AM
Problem with autoflush on Semaphore-threads for Windows dede Perl 0 07-28-2004 03:48 PM
Why does IO::Pipe::END generate an EXCEPT pipe message? lvirden@gmail.com Perl Misc 1 06-02-2004 02:17 PM
Autoflush in python cgi Gianluca Trombetta Python 1 06-02-2004 01:13 AM
CGI autoflush in Window Herman Chan Perl 0 10-09-2003 05:08 PM



Advertisments