00001 //---------------------------------------------------------------------------- 00002 /** @file SgProcess.h */ 00003 //---------------------------------------------------------------------------- 00004 00005 #ifndef SG_PROCESS_H 00006 #define SG_PROCESS_H 00007 00008 #include <ext/stdio_filebuf.h> // GCC specific 00009 #include <iosfwd> 00010 #include <memory> 00011 00012 //---------------------------------------------------------------------------- 00013 00014 /** Run a child process and provide access to its standard input and output 00015 streams. 00016 The implementation of this class is platform-dependent. Currently, only 00017 POSIX systems are supported (it also uses GCC-specific extensions to 00018 open C++ streams from file descriptors). 00019 */ 00020 class SgProcess 00021 { 00022 public: 00023 /** Constructor. 00024 @throws SgException on failure 00025 */ 00026 SgProcess(const std::string& command); 00027 00028 ~SgProcess(); 00029 00030 std::istream& Input(); 00031 00032 std::ostream& Output(); 00033 00034 private: 00035 std::auto_ptr<__gnu_cxx::stdio_filebuf<char> > m_bufIn; 00036 00037 std::auto_ptr<__gnu_cxx::stdio_filebuf<char> > m_bufOut; 00038 00039 std::auto_ptr<std::istream> m_in; 00040 00041 std::auto_ptr<std::ostream> m_out; 00042 }; 00043 00044 inline std::istream& SgProcess::Input() 00045 { 00046 return *m_in; 00047 } 00048 00049 inline std::ostream& SgProcess::Output() 00050 { 00051 return *m_out; 00052 } 00053 00054 //---------------------------------------------------------------------------- 00055 00056 #endif // SG_PROCESS_H