]> git.localhorst.tv Git - blank.git/blob - src/app/Process.hpp
test for invoking with unknown argument
[blank.git] / src / app / Process.hpp
1 #ifndef BLANK_APP_PROCESS_HPP_
2 #define BLANK_APP_PROCESS_HPP_
3
4 #include <memory>
5 #include <string>
6 #include <vector>
7
8
9 namespace blank {
10
11 class Process {
12
13 public:
14         using Arguments = std::vector<std::string>;
15         using Environment = std::vector<std::string>;
16
17 public:
18         /// launch process executing the file at given path with
19         /// given arguments and environment
20         Process(
21                 const std::string &path,
22                 const Arguments &args,
23                 const Environment &env);
24         ~Process();
25
26 public:
27         /// write to the process' input stream
28         /// data is taken from given buffer, at most max_len bytes
29         /// @return the number of bytes written
30         std::size_t WriteIn(const void *buffer, std::size_t max_len);
31         /// read from the process' output stream
32         /// data is stored in the given buffer, at most max_len bytes
33         /// @return the number of bytes read
34         std::size_t ReadOut(void *buffer, std::size_t max_len);
35         /// read from the process' error stream
36         /// data is stored in the given buffer, at most max_len bytes
37         /// @return the number of bytes read
38         std::size_t ReadErr(void *buffer, std::size_t max_len);
39
40         /// ask the process nicely to terminate
41         /// (except on win32)
42         void Terminate();
43         /// wait until the process exits and fetch its exit status
44         int Join();
45
46 private:
47         struct Impl;
48         std::unique_ptr<Impl> impl;
49
50         bool joined;
51         int status;
52
53 };
54
55 }
56
57 #endif