in reply to Re^4: To organize pipe right way.
in thread To organize pipe right way.
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.use warnings; use strict;
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 theif( $nomer_vosproizvodyshchego_protsessu=fork ){
motif.my $pid = fork(); die "Fork failed\n" unless defined $pid; if ($pid == 0) { $| = 1; exec @args; }
Not the same thing. $| only affects the current active file handle, as controlled by select and by default STDOUT.# Same thing? -- I.e. not working? $|=1; $FIFO->autoflush( 1 );
Are you sure that shouldn't be print $FIFO "pause\n";print $FIFO 'pause';
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]");for( $i=0; $i<=$#svitok_na_vosproizvedenie; $i++ ){ system( '/usr/bin/mplayer -slave -input file='.$svitok_truby.' '.$ +svitok_na_vosproizvedenie_kom[$i] ); }
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.unlink $svitok_truby;
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: To organize pipe right way.
by nikolay (Beadle) on May 07, 2016 at 12:08 UTC | |
by nikolay (Beadle) on Jun 29, 2016 at 06:34 UTC |