Function Reference
— Built-in Function: [in, out, pid] = popen2 (command, args)

Start a subprocess with two-way communication. The name of the process is given by command, and args is an array of strings containing options for the command. The file identifiers for the input and output streams of the subprocess are returned in in and out. If execution of the command is successful, pid contains the process ID of the subprocess. Otherwise, pid is −1.

For example,

          [in, out, pid] = popen2 ("sort", "-r");
          fputs (in, "these\nare\nsome\nstrings\n");
          fclose (in);
          EAGAIN = errno ("EAGAIN");
          done = false;
          do
           s = fgets (out);
           if (ischar (s))
             fputs (stdout, s);
           elseif (errno () == EAGAIN)
             sleep (0.1);
             fclear (out);
           else
             done = true;
           endif
          until (done)
          fclose (out);
              -| are
              -| some
              -| strings
              -| these