libnick 2024.9.2
A cross-platform base for native Nickvision applications.
Loading...
Searching...
No Matches
process.h
Go to the documentation of this file.
1
23#ifndef PROCESS_H
24#define PROCESS_H
25
26#include <cstdio>
27#include <filesystem>
28#include <memory>
29#include <mutex>
30#include <string>
31#include <thread>
32#include <vector>
33#include "events/event.h"
35#ifdef _WIN32
36#include <windows.h>
37#else
38#include <sys/types.h>
39#endif
40
41namespace Nickvision::System
42{
46 class Process
47 {
48 public:
55 Process(const std::filesystem::path& path, const std::vector<std::string>& args = {});
65 const std::filesystem::path& getPath() const;
75 bool isRunning() const;
80 bool hasCompleted() const;
85 int getExitCode() const;
90 const std::string& getOutput() const;
95 bool start();
100 bool kill();
108
109 private:
113 void watch();
114 mutable std::mutex m_mutex;
115 std::filesystem::path m_path;
116 std::vector<std::string> m_args;
118 bool m_running;
119 bool m_completed;
120 int m_exitCode;
121 std::string m_output;
122 std::thread m_watchThread;
123#ifdef _WIN32
124 HANDLE m_read;
125 HANDLE m_write;
126 PROCESS_INFORMATION m_pi;
127#else
128 int m_pipe[2];
129 pid_t m_pid;
130#endif
131 };
132}
133
134#endif //PROCESS_H
An event that can have handlers subscribe to it, which in turn will be called when the event is invok...
Definition event.h:49
A managed process.
Definition process.h:47
bool isRunning() const
Gets whether or not the process is running.
Process(const std::filesystem::path &path, const std::vector< std::string > &args={})
Constructs a Process.
~Process()
Destructs a Process.
bool start()
Starts the process.
int getExitCode() const
Gets the exit code of the process.
bool kill()
Kills the process.
const std::string & getOutput() const
Gets the console output of the process.
Events::Event< ProcessExitedEventArgs > & exited()
Gets the event for when the process has exited.
int waitForExit()
Waits for the process to exit.
const std::filesystem::path & getPath() const
Gets the path of the process.
bool hasCompleted() const
Gets whether or not the process has completed.
Definition deploymentmode.h:27