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