Sorry, I neglected to set flush on the pipe, which is why you saw the issue. That can be accomplished by explicitly importing IO::Handle and calling autoflush. If I write a complete, self-contained script wrapping date, it might look like:
#!/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; }
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):
my @args = ('/usr/bin/mplayer', '-slave', '-input', "file=$svitok_trub +y", $svitok_na_vosproizvedenie_kom[$i]);
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,
perl -E'$|=1;print,sleep 1 for 0..9' | perl script.pl
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.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.