#include int main(int argc, char** argv) { /* launch a process that will grep for the text "xes" and write its stdout to ./output */ /* caution... if the command is not found the return will still return a FILE* */ FILE* grep = popen("grep \"xes\" > output", "w"); /* write text to the stdin of grep process */ fprintf(grep, "boxes\n"); fprintf(grep, "coins\n"); fprintf(grep, "taxes\n"); /* close the pipe */ int r = pclose(grep); if (r) { fprintf(stdout, "error. return code from pclose %d\n", r); } return 0; }