WvStreams
wvpipelogex.cc
00001 /*
00002  * A WvPipe and WvLog example.
00003  *
00004  * This program allows you to enter bash commands, runs them, and pipes the
00005  * output back to you
00006  */
00007 
00008 #include "wvpipe.h"
00009 #include "wvlog.h"
00010 
00011 int main(int argc, char **argv)
00012 {
00013     const char *_av[] = {
00014         "/bin/bash",
00015         NULL
00016     };
00017     const char **av = (argc < 2) ? _av : (const char **)(argv + 1);
00018 
00019     WvLog log(av[0]);
00020     WvPipe p(av[0], av, true, false, false);
00021 
00022     wvcon->autoforward(p);
00023     p.autoforward(*wvcon);
00024 
00025     p.write("test string\r\n");
00026 
00027     while (p.isok() && wvcon->isok())
00028     {
00029         if (p.select(100))
00030             p.callback();
00031         if (wvcon->select(100))
00032             wvcon->callback();
00033     }
00034 
00035     p.flush_then_close(50000);
00036     while (p.isok())
00037     {
00038         log("Flushing...\n");
00039         if (p.select(1000))
00040             p.callback();
00041     }
00042 
00043     if (p.child_exited())
00044         log(WvLog::Notice, "Exited (return code == %s)\n",
00045             p.exit_status());
00046 
00047     _exit(0); // don't kill the subtask
00048 
00049     return 0;
00050 }