Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2002-07-26 16:49:26


Close, but I'd also want another stream for sending stuff from the parent
to the child, the child's stdin.

On Fri, 26 Jul 2002, Jeff Garland wrote:

jeff> How about this:
jeff>
jeff> //usage:
jeff> systemistream s("./hello.exe"); //execute hello.cpp put results stream
jeff> std::string data;
jeff> while (getline(s,data)) {
jeff> std::cout << data << std::endl;
jeff> }
jeff>
jeff> //! An input stream built from the result of running a shell command
jeff> /*! This class is intended to facilitate large scale integration by similar
jeff> * to the perl "open" command by combining the concept of an input stream
jeff> * and the common idea of a spawning a subprocess to perform a task.
jeff> *
jeff> * The class takes the definition optionally tasks the the subprocess
jeff> * execution string as the a construction argument and will automatically
jeff> * spawn the child process. Alternatively, the child process can be created
jeff> * later using the open method.
jeff> */
jeff> class systemistream : public std::basic_istream<char, std::char_traits<char> > {
jeff> public:
jeff> systemistream(const std::string& command="");
jeff> ~systemistream();
jeff> void open(const std::string& command);
jeff> void close();
jeff> private:
jeff> std::basic_filebuf<char, std::char_traits<char> >* buf_;
jeff>
jeff> };
jeff>
jeff> It's a bit of a hack, but it works...
jeff>
jeff> Jeff
jeff> _______________________________________________
jeff> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
jeff>

----------------------------------------------------------------------
 Jeremy Siek http://php.indiana.edu/~jsiek/
 Ph.D. Student, Indiana Univ. B'ton email: jsiek_at_[hidden]
 C++ Booster (http://www.boost.org) office phone: (812) 855-3608
----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk