00001 #ifndef DVUTIL_PSTREAM_H 00002 #define DVUTIL_PSTREAM_H 00003 // $Id: iopstream.h,v 1.3 2008/03/13 21:17:13 dvermeir Exp $ 00004 00005 #include <string> 00006 #include <iostream> 00007 #include <stdexcept> 00008 #include <dvutil/process.h> 00009 00010 namespace Dv { 00011 namespace Util { 00012 00013 /** Start a process with its standard input/output connected to an 00014 * iostream. 00015 */ 00016 class iopstream: public std::iostream, public Dv::Util::Process { 00017 public: 00018 /** Create an input/output stream from/to a process running @c 00019 * command. The process is created using @c execl with 00020 * argument 00021 * <pre> 00022 * /bin/sh -c command 00023 * </pre> 00024 * Data written to the stream will appear on the standard input of 00025 * the process. The standard output of the process can be read from 00026 * the stream. 00027 * @param command which will be run using <code>/bin/sh -c command</code> 00028 * @param min_debug_level for when the object is connected to a 00029 * debug master 00030 * @sa Dv::Debugable 00031 * @exception std::runtime_error if anything goes wrong. 00032 */ 00033 iopstream(const std::string& command, unsigned int min_debug_level = 1) 00034 throw (std::runtime_error); 00035 00036 /** Close stream. 00037 * Wait for command to finish, then return its exit status. 00038 * After a close, the stream is unusable. 00039 * @return exit status of command as returned by main(). 00040 * @warning A negative exit status gets converted to a 00041 * positive number, i.e. -1 becomes 255. 00042 * @exception std::runtime_error if command did not exit normally or any other problem. 00043 */ 00044 int close() throw (std::runtime_error); 00045 00046 /** Destructor. 00047 * @exception std::runtime_error if anything goes wrong. 00048 */ 00049 ~iopstream() throw (std::runtime_error); 00050 00051 private: 00052 void start() throw (std::runtime_error); 00053 }; 00054 } 00055 } 00056 #endif
dvutil-1.0.10 | [ 5 December, 2009] |