unbuffered i/o to a pipe

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am playing with a raspberry pi with some generated stereo piped to  
pacat. This is for a larger project but for this I just have a sine  
wave that moves across the speakers for a few seconds. It stutters so  
I wondered if there is any buffering going on when you open like so:

my $pacat = sprintf "| pacat --................
open my $PACAT, $pacat or die "Can't open $pacat $!";

If there is buffering how does one turn it off?  

my $old_fh = select $PACAT; $| = 1; select $old_fh;  

Does not make any difference. Of course it may be something completely
different causing the stutter - but things like mplayer work fine with
no stutter.

Dave Saville

Re: unbuffered i/o to a pipe

Quoted text here. Click to load it

It does, cf

use POSIX;

my ($fh, $rc);
my ($rd, $wr, $fh);

pipe($rd, $wr);

if (fork() == 0) {
    while ($rc = <$rd>) {
    print STDERR ("pong\n");



$fh = select($wr);
$| = 1;

for (0 .. 9) {
    print STDERR ("ping\n");
    print $wr ("ping\n");


Depending on whether autoflush is set or not, this will either print
ping - pong alternatingly or print 10 pings followed by 10 pongs. But
you should really bypass the buffering altogether for 'realtime
communication', aka 'use syswrite'.

Site Timeline