Re: [CODE] Callback functions (update - Ver 2)

From: Daniel A. Koepke (
Date: 06/15/01

On Fri, 15 Jun 2001, DOOMer 2k wrote:

> Well, Dak, the actual reason I chose to use system() over popen() was
> because I have never heard of popen() until now.

Consider switching.  The use of pipes is not, at all, different from using
files.  The only actual difference is that you call popen() and pclose()
instead of fopen() and fclose().  The rest is exactly the same, down to
popen() returning a FILE pointer and reading/writing using fgets(),
fprintf(), etc.  Code that looks like

  char line[256];
  FILE *tmpfp;

  tmpfp = fopen("temporary", "w");
  fprintf(tmpfp, "Text to be processed.\n");

  system("filter < temporary > output");

  tmpfp = fopen("output", "r");
  fgets(line, 256, tmpfp);


is better written

  char line[256];
  FILE *pipe = popen("filter");

  fprintf(pipe, "Text to be processed.\n");
  fgets(line, 256, pipe);

That is, as I said (and I hope you didn't take me as being rude, I wasn't
attempting to be), pipes are meant exactly for this purpose.  It's more
compact, direct, efficient, secure, and conceptually simpler than using
system() and temporary files.

Daniel A. Koepke (dak),
Caveat emptor: I say what I mean and mean what I say.  Listen well.
Caveat venditor: Say what you mean, mean what you say.  Say it well.

   | FAQ: |
   | Archives: |

This archive was generated by hypermail 2b30 : 12/05/01 PST