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"); fclose(tmpfp); system("filter < temporary > output"); tmpfp = fopen("output", "r"); fgets(line, 256, tmpfp); fclose(tmpfp); unlink("temporary"); unlink("output"); is better written char line[256]; FILE *pipe = popen("filter"); fprintf(pipe, "Text to be processed.\n"); fgets(line, 256, pipe); pclose(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), dkoepke@circlemud.org 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: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html | | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html | +---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/05/01 PST