use warnings; use strict;
Your posted code does not pass strict. This tells me you are not posting the same code you are running. The confusion on this thread is largely driven by not being able to reach mutual understanding of issues. See How do I post a question effectively?. Do not include strict if you don't use it, and don't post code that doesn't compile.
if( $nomer_vosproizvodyshchego_protsessu=fork ){
This does not consider the possibility that the fork has returned undef, i.e., has failed. It also means you need to have the rest of your code, none of which is shared, indented into if blocks. That's why I keep using the
my $pid = fork(); die "Fork failed\n" unless defined $pid; if ($pid == 0) { $| = 1; exec @args; }
motif.
# Same thing? -- I.e. not working? $|=1; $FIFO->autoflush( 1 );
Not the same thing. $| only affects the current active file handle, as controlled by select and by default STDOUT.
print $FIFO 'pause';
Are you sure that shouldn't be print $FIFO "pause\n";
for( $i=0; $i<=$#svitok_na_vosproizvedenie; $i++ ){ system( '/usr/bin/mplayer -slave -input file='.$svitok_truby.' '.$ +svitok_na_vosproizvedenie_kom[$i] ); }
So you are opening more than one instance of mplayer? I guess this is supposed to be a playlist. Using a blocking call to system to control playing makes sense; the exec solution here would require monitoring the child for an exit status prior to spawning another child, which has an unnecessary number of moving parts. I think your call would be cleaner with interpolating double quotes, but that's cosmetic. system("/usr/bin/mplayer -slave -input file=$svitok_truby $svitok_na_vosproizvedenie_kom[$i]");
unlink $svitok_truby;
The reason I wrapped this in an END block was so that it would always execute, even when the script dies. You never want the file lying around afterward.

Finally, have you tried the example cases I gave you? Have you tried isolating where the lag could be? Rather than worrying about all the other stuff, just try looping over a pause:

#!/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 = ('/usr/bin/mplayer', '-slave', '-input', "file=$svitok_trub +y", '/tmp/1.flac'); 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); for my $i (1 .. 10) { print $FIFO 'pause'; sleep 1; } print $FIFO 'quit'; close($FIFO); END { unlink $svitok_truby; }

#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^5: 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.