From bug-octave-request at bevo dot che dot wisc dot edu Wed Jan 26 16:22:16 2000 Subject: popen2 broken? From: "John W. Eaton" To: bsapp at lanl dot gov Cc: bug-octave at bevo dot che dot wisc dot edu Date: Wed, 26 Jan 2000 16:22:36 -0600 (CST) On 26-Jan-2000, Ben Sapp wrote: | In octave-2.1.23 on Linux and octave-2.1.24 on IRIX the example given in | the documentation for popen2 fails. It creates a new octave process. | These processes fight for stdin. Here is the output: | | ----------------------------------------------------------------- | octave:6> OCTAVE_VERSION | OCTAVE_VERSION = 2.1.23 | octave:7> [in, out, pid] = popen2("sort","-nr") | error: octave_base_value::double_value (): wrong type argument `list' | error: octave_base_value::double_value (): wrong type argument `list' | error: file id must be a file object, string, or integer value | error: evaluating if command near line 72, column 2 | error: evaluating if command near line 68, column 7 | error: evaluating if command near line 63, column 5 | error: evaluating if command near line 57, column 3 | error: called from `popen2' in file | `/usr/local/share/octave/2.1.23/m/miscellaneous/popen2.m' | octave:7> error: file id must be a file object, string, or integer value | error: evaluating if command near line 72, column 2 | error: evaluating if command near line 68, column 7 | error: evaluating if command near line 63, column 5 | error: evaluating if command near line 57, column 3 | error: called from `popen2' in file | `/usr/local/share/octave/2.1.23/m/miscellaneous/popen2.m' | octave:7> | ------------------------------------------------------------------- Here is a solution for the `wrong type' errors: Index: popen2.m =================================================================== RCS file: /usr/local/cvsroot/octave/scripts/miscellaneous/popen2.m,v retrieving revision 1.12 diff -u -r1.12 popen2.m --- popen2.m 2000/01/13 08:40:15 1.12 +++ popen2.m 2000/01/26 22:20:34 at @ -71,14 +71,14 @@ if (pid == 0) - fclose (stdin_pipe (2)); - fclose (stdout_pipe (1)); + fclose (nth (stdin_pipe, 2)); + fclose (nth (stdout_pipe, 1)); - dup2 (stdin_pipe (1), stdin); - fclose (stdin_pipe (1)); + dup2 (nth (stdin_pipe, 1), stdin); + fclose (nth (stdin_pipe, 1)); - dup2 (stdout_pipe (2), stdout); - fclose (stdout_pipe (2)); + dup2 (nth (stdout_pipe, 2), stdout); + fclose (nth (stdout_pipe, 2)); if (exec (command, args) < 0) error ("popen2: unable to start process `%s'", command); at @ -87,14 +87,14 @@ elseif (pid) - fclose (stdin_pipe (1)); - fclose (stdout_pipe (2)); + fclose (nth (stdin_pipe, 1)); + fclose (nth (stdout_pipe, 2)); - if (fcntl (stdout_pipe (1), __F_SETFL__, __O_NONBLOCK__) < 0) + if (fcntl (nth (stdout_pipe, 1), __F_SETFL__, __O_NONBLOCK__) < 0) error ("popen2: error setting file mode"); else - in = stdin_pipe (2); - out = stdout_pipe (1); + in = nth (stdin_pipe, 2); + out = nth (stdout_pipe, 1); endif elseif (pid < 0) Unfortunately, I'm still having problems with reading from the output end of the process. It seems to hang, and I don't know why. If anyone can offer clues, I'd appreciate it... jwe ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------