still popen2 problems

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

still popen2 problems

Allan E. Strand

I sent a vague message to the list a few days ago about popen2.
Having received no response, I decided to post a more specific example
of my problem.

The follwing code comes directly from the octave info pages:

[in, out, pid] = popen2 ("sort", "-nr");
fputs (in, "these\nare\nsome\nstrings\n");
fclose (in);
while (isstr (s = fgets (out)))
  fputs (stdout, s);
fclose (out);

if I execute these comamnds interactively, they _always_ produce the
correct result.  When I place them in a file and call them as a
script, I either get no result at all or a warning that there is a
broken pipe and (of course) no result.

Does anyone have an idea of what the problem might be?


p.s.  NetBSD 1.2.1, P133, octave 2.0.5

Allan E. Strand                Internet:   [hidden email]
Department of Biology
New Mexico State University    Phone:      (505) 646-1150
Las Cruces, New Mexico  88003  FAX:        (505) 646-5665

Reply | Threaded
Open this post in threaded view

Re: still popen2 problems

Dirk Eddelbuettel-2


Two things come to mind:

 - 2.0.5 is too old. You should upgrade to 2.0.9. Things like this _did_
   change. I played myself with two-way pipes under 2.0.x and JWE supplied
   a patch, but I cannot remember against which 2.0.x version. Check the
   mailing list archives at the usual site.

 - Check the manual. Octave might 'know' when it is called interactively.
   You for sure want to check out 'fflush(stdout)' and the variable
   'page_output_immediately' . They are both documented on the same manual
   page. Quickest is
        $ info octave "input and output"
   if info knows where to find your Octave texinfo documentation.

Cheers, Dirk

 [hidden email]   PGP KeyID 1024/6D7F08DD