WvStreams
wvpipelogex.cc
1 /*
2  * A WvPipe and WvLog example.
3  *
4  * This program allows you to enter bash commands, runs them, and pipes the
5  * output back to you
6  */
7 
8 #include "wvpipe.h"
9 #include "wvlog.h"
10 
11 int main(int argc, char **argv)
12 {
13  const char *_av[] = {
14  "/bin/bash",
15  NULL
16  };
17  const char **av = (argc < 2) ? _av : (const char **)(argv + 1);
18 
19  WvLog log(av[0]);
20  WvPipe p(av[0], av, true, false, false);
21 
22  wvcon->autoforward(p);
23  p.autoforward(*wvcon);
24 
25  p.write("test string\r\n");
26 
27  while (p.isok() && wvcon->isok())
28  {
29  if (p.select(100))
30  p.callback();
31  if (wvcon->select(100))
32  wvcon->callback();
33  }
34 
35  p.flush_then_close(50000);
36  while (p.isok())
37  {
38  log("Flushing...\n");
39  if (p.select(1000))
40  p.callback();
41  }
42 
43  if (p.child_exited())
44  log(WvLog::Notice, "Exited (return code == %s)\n",
45  p.exit_status());
46 
47  _exit(0); // don't kill the subtask
48 
49  return 0;
50 }
WvPipe
Implementation of a WvPipe stream.
Definition: wvpipe.h:32
WvStream::select
bool select(time_t msec_timeout)
Return true if any of the requested features are true on the stream.
Definition: wvstream.h:376
WvStream::callback
virtual void callback()
if the stream has a callback function defined, call it now.
Definition: wvstream.cc:401
WvLog
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:56
WvStream::autoforward
void autoforward(WvStream &s)
set the callback function for this stream to an internal routine that auto-forwards all incoming stre...
Definition: wvstream.cc:362
WvStream::isok
virtual bool isok() const
return true if the stream is actually usable right now
Definition: wvstream.cc:445