Go to the documentation of this file.00001
00020 #ifndef COIL_PROCESS_H
00021 #define COIL_PROCESS_H
00022
00023 #include <windows.h>
00024 #include <tchar.h>
00025 #include <string>
00026 #include <coil/stringutil.h>
00027
00028 namespace coil
00029 {
00030
00057 int launch_shell(std::string command);
00058
00059 int daemon(int nochdir, int noclose);
00060
00061
00062 class Popen
00063 {
00064 FILE* m_fd;
00065 public:
00066 Popen(std::string cmd, std::string mode)
00067 {
00068 m_fd = _popen(cmd.c_str(), mode.c_str());
00069 }
00070 virtual ~Popen()
00071 {
00072 if (m_fd != 0)
00073 {
00074 _pclose(m_fd);
00075 }
00076 }
00077 bool isEof()
00078 {
00079 if (feof(m_fd)) { return true; }
00080 return false;
00081 }
00082 std::string getline()
00083 {
00084 if (m_fd == 0) { return ""; }
00085 if (feof(m_fd)) { return ""; }
00086 char str[512];
00087 fgets(str, 512, m_fd);
00088 std::string line(str);
00089 return line;
00090 }
00091 };
00092 };
00093
00094 inline FILE* popen(const char* cmd, const char* mode)
00095 {
00096 return _popen(cmd, mode);
00097 }
00098
00099 inline void pclose(FILE* fd)
00100 {
00101 _pclose(fd);
00102 }
00103
00104 #endif // COIL_PROCESS_H