1
2
3
4
5
6 #ifndef SOULNG_UTIL_PROCESS_INCLUDED
7 #define SOULNG_UTIL_PROCESS_INCLUDED
8 #include <soulng/util/UtilApi.hpp>
9 #include <string>
10
11 namespace soulng { namespace util {
12
13 class ProcessImpl;
14
15 class Process
16 {
17 public:
18 enum class Redirections : int
19 {
20 none= 0,
21 processStdIn= 1 << 0,
22 processStdOut= 1 << 1,
23 processStdErr= 1 << 2
24 };
25 enum class StdHandle : int
26 {
27 stdOut= 1, stdErr= 2
28 };
29 Process(const std::string& command, Redirections redirections);
30 ~Process();
31 bool Running();
32 void WaitForExit();
33 int ExitCode() const;
34 void Terminate();
35 bool Eof(StdHandle handle);
36 std::string ReadLine(StdHandle handle);
37 std::string ReadToEnd(StdHandle handle);
38 void WriteLine(const std::string& line);
39 private:
40 ProcessImpl* impl;
41 };
42
43 constexpr Process::Redirections operator|(Process::Redirections left, Process::Redirections right)
44 {
45 return Process::Redirections(int(left) | int(right));
46 }
47
48 constexpr Process::Redirections operator&(Process::Redirections left, Process::Redirections right)
49 {
50 return Process::Redirections(int(left) & int(right));
51 }
52
53 int GetPid();
54
55 } }
56
57 #endif // SOULNG_UTIL_PROCESS_INCLUDED