pike.git / lib / modules / Process.pmod

version» Context lines:

pike.git/lib/modules/Process.pmod:248: Inside #if defined(__NT__)
   s = "\"" + s + "\"";    return create_process(({ "cmd", "/c", s }),data);   #elif defined(__amigaos__)    return create_process(split_quoted_string(s),data);   #else /* !__NT__||__amigaos__ */    return create_process(({ "/bin/sh", "-c", s }),data);   #endif /* __NT__||__amigaos__ */      }    + //! @decl string popen(string command) + //! Executes the @[command], waits until it has finished and returns + //! the result as a string. +  + //! @decl Stdio.FILE popen(string command, string mode)   //! Open a "process" for reading or writing. The @[command] is executed   //! as a shell statement ("/bin/sh -c command" for Unix,   //! "cmd /c command" for Windows). The parameter @[mode] should   //! be one of the following letters:   //! @string   //! @value 'r'   //! Open for reading. Data written by the process to stdout   //! is available for read.   //! @value 'w'   //! Open for writing. Data written to the file is available   //! to the process on stdin.   //! @endstring - //! If no @[mode] is passed, read mode is assumed. - Stdio.FILE fpopen(string s, string|void mode) +  + Stdio.FILE|string popen(string s, string|void mode) { +  if(mode) +  return fpopen(s,mode); +  else +  return fpopen(s)->read(); + } +  + static Stdio.FILE fpopen(string s, string|void mode)   { -  if (!mode) mode = "r"; +     Stdio.FILE f = Stdio.FILE();    if (!f) error("Popen failed. (couldn't create file)\n");       Stdio.File p = f->pipe();    if(!p) error("Popen failed. (couldn't create pipe)\n");       if (mode == "w")    spawn(s, p, 0, 0, destruct, f);    else    spawn(s, 0, p, 0, destruct, f);    p->close();    destruct(p);       return f;   }    - //! Works as @[fpopen], but blocks until the command completes and - //! returns the resulting string. - string popen(string s) { -  return fpopen(s)->read(); - } -  +    //!   int system(string s)   {    return spawn(s)->wait();   }      #ifndef __NT__   #if constant(fork)   constant fork = predef::fork;   #endif