Unbuffered piped command output?

  • Thread starter Bryan K. Wright
  • Start date
B

Bryan K. Wright

Hi folks,

The following seems simple, but it's driving me crazy.
I'd like to create a command pipe with open, like this:

open ( CMD, "mycommand |");

then print out each line of the command's output AS IT HAPPENS.
Here's what I've tried:

#!/usr/bin/perl
use strict;
use FileHandle;
STDOUT->autoflush(1);
open ( COMMAND, "mycommand |" ) or die "Can't run command: $!\n";
COMMAND->autoflush(1);
while (<COMMAND>) {
print;
}
close ( COMMAND );

But the command's output is still buffered until the command
finishes. What am I doing wrong here?

Thanks,
Bryan
--
===============================================================================
Bryan Wright |"If you take cranberries and stew them like
Physics Department | applesauce, they taste much more like prunes
University of Virginia | than rhubarb does." -- Groucho
Charlottesville, VA 22901 |
(434) 924-7218 | (e-mail address removed)
===============================================================================
 
S

Scott W Gifford

Bryan K. Wright said:
Hi folks,

The following seems simple, but it's driving me crazy.
I'd like to create a command pipe with open, like this:

open ( CMD, "mycommand |");

then print out each line of the command's output AS IT HAPPENS.

A discussion of this exact problem is going on right now in the thread
with subject:

Input from subprocess called using open() buffered?

The answers there may be helpful.

-----ScottG.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top