vkmEngine 1.0.15
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
child_process.h
1#pragma once
2
3#include <filesystem>
4#include <mutex>
5#include <string>
6#include <thread>
7#include <vector>
8
9namespace Vkm::Engine {
10
22class ChildProcess {
23 public:
24 ChildProcess() = default;
25 ~ChildProcess();
26
27 ChildProcess(const ChildProcess& other) = delete;
28 ChildProcess& operator=(const ChildProcess& other) = delete;
29
30 ChildProcess(ChildProcess && other) = delete;
31 ChildProcess& operator=(ChildProcess && other) = delete;
32
33 public:
42 bool start(
43 const std::filesystem::path& program,
44 const std::vector<std::string>& args,
45 const std::filesystem::path& workingDir = {}
46 );
47
51 void stop();
52
58 std::string takeOutput();
59
65 bool running();
66
72 int exitCode();
73
74 private:
76 void readUntilExit();
77
78 private:
79 std::mutex m_mutex;
80 std::string m_output;
81 int m_exitCode = -1;
82 bool m_running = false;
83 std::thread m_reader;
84
85#if defined(_WIN32)
86 void* m_process = nullptr;
87 void* m_job = nullptr;
88 void* m_pipe = nullptr;
89#else
90 int m_pid = 0;
91 int m_pipeFd = -1;
92#endif
93};
94
95} // namespace Vkm::Engine
void stop()
End the program and everything it started, and wait for it.
int exitCode()
How the last program exited.
bool running()
Whether a program was started and has not yet exited.
std::string takeOutput()
Take the output that arrived since the last call.
bool start(const std::filesystem::path &program, const std::vector< std::string > &args, const std::filesystem::path &workingDir={})
Start program with args in workingDir, ending any program started before.