I did understand your code not fully. -- It would be far better for me (to understand your answer), had you applied only necessary changes to my code structure -- not changing everything by the way. I would not ask you to explain many things because, it could be hard, so, i did apply what is seems me relevant, and can say, that it is works, but worse -- insted of sometimes, i had to press a key twice-thrice, now the number went up to seven! -- If i but write to pipe the PERLs' way instead of Shell's. Here is the code.
my $FIFO=undef; mkfifo( $svitok_truby, 0700 ) || die '&#1054;&#1096;&#1080;&#1073;&#10 +82;&#1072; &#1089;&#1086;&#1079;&#1076;&#1072;&#1085;&#1080;&#1103; & +#1090;&#1088;&#1091;&#1073;&#1099; '.$svitok_truby.' : '.$!; local $SIG{CHLD} = "IGNORE"; if( $nomer_vosproizvodyshchego_protsessu=fork ){ $|=1; open( $FIFO, '>', $svitok_truby ) || die '&#1053;&#1077; &#1086;&#10 +90;&#1082;&#1088;&#1099;&#1090;&#1100; &#1090;&#1088;&#1091;&#1073;&# +1091; '.$svitok_truby.' &#1085;&#1072; &#1079;&#1072;&#1087;&#1080;&# +1089;&#1100; : '.$!; <sniped> print $FIFO 'pause'; <sniped> }else{ exec '/usr/bin/mplayer -slave -input file='.$svitok_truby.' /tmp/1.f +lac'; } close( $FIFO ); unlink $svitok_truby;

Just one question, is there a flush command -- to execute after each writing to pipe?

I did test more and have noticed weird connection between input in parent and pausing of mplayer, though to pipe was sent nothing at all -- parent just does its own work, w/o sending a thing to pipe, for example:

mkfifo( $svitok_truby, 0700 ) || die '&#1054;&#1096;&#1080;&#1073;&#10 +82;&#1072; &#1089;&#1086;&#1079;&#1076;&#1072;&#1085;&#1080;&#1103; & +#1090;&#1088;&#1091;&#1073;&#1099; '.$svitok_truby.' : '.$!; # &#1059;&#1087;&#1088;&#1072;&#1074;&#1083;&#1103;&#1102;&#1097;&#107 +2;&#1103; &#1095;&#1072;&#1089;&#1090;&#1100; ("&#1088;&#1086;&#1076; +&#1080;&#1090;&#1077;&#1083;&#1100;"). if( $nomer_vosproizvodyshchego_protsessu=fork ){ $|=1; use Term::ReadKey; ReadMode 'cbreak'; # Parent while( 1 ){ $knopka=&ReadKey( 0 ); if( $knopka eq '/' ){ system( '/bin/date' ); }elsif( $knopka eq $knopka_vyhodu ){ system( '/bin/echo quit >'.$svitok_truby ); last; } } }else{ ## Child for( $i=0; $i<=$#svitok_na_vosproizvedenie; $i++ ){ system( '/usr/bin/mplayer -slave -input file='.$svitok_truby.' '.$ +svitok_na_vosproizvedenie_kom[$i] ); } } ReadMode 'normal'; unlink $svitok_truby;

So, when i press key / -- parent just outputs date. But many times pressing, once, «mplayer2» will pause playing -- though nothing was sent to pipe! -- And that input-pipe relation i can not understand. Module «Term» does not have influence -- i had the same w/ the «read» function.

Oh! The site terribly corrupts my input!

Thanks for your answers.


In reply to Re^2: To organize pipe right way. by nikolay
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.