To modify this from piping into the toy echo program, you would swap @args (including the here-doc, which runs until EOC) to whatever is appropriate for your program, probably (untested):#!/usr/bin/perl use strict; use warnings; use POSIX qw( mkfifo ); use IO::Handle; my $svitok_truby = 'tmp.pp'; mkfifo( $svitok_truby, 0700 ) || die "Pipe fail; $svitok_truby : $!" +; local $SIG{CHLD} = "IGNORE"; my @args = ('perl','-MIO::Handle','-E',<<'EOC',$svitok_truby); $| = 1; open my $fh, "<", $ARGV[0]; while(read $fh, my($char), 1) { print $char; } EOC my $pid = fork(); die "Fork failed\n" unless defined $pid; if ($pid == 0) { exec @args; } open (my $FIFO, '>', $svitok_truby) || die "can't open $svitok_truby: + $!"; $FIFO->autoflush(1); while(read STDIN, my($char), 1) { print $FIFO $char; } close($FIFO); END { unlink $svitok_truby; }
It's possible you will still see buffering issues depending on your terminal, because many terminal programs buffer STDIN by default. To test if that is the problem, you can pipe in commands. So, for my toy above,my @args = ('/usr/bin/mplayer', '-slave', '-input', "file=$svitok_trub +y", $svitok_na_vosproizvedenie_kom[$i]);
will slowly print 0 - 9 on the screen, one character a second. For your case, you might want to try pausing and unpausing music once per second.perl -E'$|=1;print,sleep 1 for 0..9' | perl script.pl
TLDR: use IO::Handle; and $FIFO->autoflush(1); will set the pipe to hot.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
In reply to Re^3: To organize pipe right way.
by kennethk
in thread To organize pipe right way.
by nikolay
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |