home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / IPC::Open2.z / IPC::Open2
Encoding:
Text File  |  1998-10-30  |  3.1 KB  |  133 lines

  1.  
  2.  
  3.  
  4. IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222((((3333))))                                                    IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      IPC::Open2, open2 - open a process for both reading and writing
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.          use IPC::Open2;
  13.          $pid = open2(\*RDR, \*WTR, 'some cmd and args');
  14.            # or
  15.          $pid = open2(\*RDR, \*WTR, 'some', 'cmd', 'and', 'args');
  16.  
  17.  
  18. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  19.      The _o_p_e_n_2() function spawns the given $cmd and connects $rdr for reading
  20.      and $wtr for writing.  It's what you think should work when you try
  21.  
  22.          open(HANDLE, "|cmd args|");
  23.  
  24.      The write filehandle will have autoflush turned on.
  25.  
  26.      If $rdr is a string (that is, a bareword filehandle rather than a glob or
  27.      a reference) and it begins with ">&", then the child will send output
  28.      directly to that file handle.  If $wtr is a string that begins with "<&",
  29.      then WTR will be closed in the parent, and the child will read from it
  30.      directly.  In both cases, there will be a _d_u_p(2) instead of a _p_i_p_e(2)
  31.      made.
  32.  
  33.      _o_p_e_n_2() returns the process ID of the child process.  It doesn't return
  34.      on failure: it just raises an exception matching /^open2:/.
  35.  
  36. WWWWAAAARRRRNNNNIIIINNNNGGGG
  37.      It will not create these file handles for you.  You have to do this
  38.      yourself.  So don't pass it empty variables expecting them to get filled
  39.      in for you.
  40.  
  41.      Additionally, this is very dangerous as you may block forever.  It
  42.      assumes it's going to talk to something like bbbbcccc, both writing to it and
  43.      reading from it.  This is presumably safe because you "know" that
  44.      commands like bbbbcccc will read a line at a time and output a line at a time.
  45.      Programs like ssssoooorrrrtttt that read their entire input stream first, however,
  46.      are quite apt to cause deadlock.
  47.  
  48.      The big problem with this approach is that if you don't have control over
  49.      source code being run in the child process, you can't control what it
  50.      does with pipe buffering.  Thus you can't just open a pipe to cat -v and
  51.      continually read and write a line from it.
  52.  
  53. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  54.      See the _I_P_C::_O_p_e_n_3 manpage for an alternative that handles STDERR as
  55.      well.  This function is really just a wrapper around _o_p_e_n_3().
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222((((3333))))                                                    IIIIPPPPCCCC::::::::OOOOppppeeeennnn2222((((3333))))
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.                                                                         PPPPaaaaggggeeee 2222
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.