00001
00002
00003 #ifndef BASE_PROCESS_H
00004 #define BASE_PROCESS_H
00005
00006 #ifdef _WIN32
00007 #define WIN32_LEAN_AND_MEAN
00008 #include <windows.h>
00009 #else
00010 #include <unistd.h>
00011 #endif
00012 #include "File.h"
00013
00014 namespace base {
00016
00020 class PPBASE_EXPORT Process {
00021 public:
00022 #ifdef _WIN32
00023 typedef DWORD pid_type;
00024 #else
00025 typedef pid_t pid_type;
00026 #endif
00027
00029 enum {
00030 execCaptureStdIo = 1,
00031 execMergeStdErrAndStdOut = 2,
00032 execInheritHandles = 4
00033 };
00034
00036 Process();
00037
00039 ~Process();
00040
00042
00045 void execute(int flags = 0);
00046
00048
00051 bool exitedBySignal() const;
00052
00054
00057 int getExitCode() const;
00058
00060
00063 int getExitSignal() const;
00064
00070 static int getCurrentProcessId();
00071
00073
00076 File *getStdErr();
00077
00079
00082 File *getStdIn();
00083
00085
00088 File *getStdOut();
00089
00091
00094 void setArguments(const std::vector<String> &arguments);
00095
00097
00100 void setArguments(const String &arguments);
00101
00103
00106 void setProgram(const String &program);
00107
00109
00117 void terminate(int exitcode);
00118
00120
00124 bool wait(unsigned timeout = 0);
00125
00126 private:
00128 void closeStdIoStreams();
00129
00130 std::vector<String> _arguments;
00131 int _exitcode;
00132 String _program;
00133 #ifdef _WIN32
00134 PROCESS_INFORMATION _pi;
00135 #else
00136 pid_type _pid;
00137 #endif
00138 File *_stderr;
00139 File *_stdin;
00140 File *_stdout;
00141
00142 DISALLOW_COPY_CONSTRUCTOR_AND_ASSIGNMENT(Process);
00143 };
00144 }
00145
00146 #endif