IPC with pipes, demo of 'popen'

#include <stdio.h>
#include <unistd.h>

int main()
{
        FILE* stream = popen ("sort", "w");
        fprintf (stream, "This is a test.\n" );
        fprintf (stream, "Hello, world.\n");
        fprintf (stream, "My dog has fleas.\n");
        fprintf (stream, "This program is great.\n");
        fprintf (stream, "One fish, two fish.\n");
        return pclose (stream);
}

 

posted @ 2014-03-21 19:55  samu  阅读(209)  评论(0编辑  收藏  举报