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.