ProcLib 0.0.1.0
A cross-platform process runner.
Loading...
Searching...
No Matches
process.hxx
Go to the documentation of this file.
1//
2// Copyright (c) 2026 Jamie Kenyon. All Rights Reserved.
3//
4
5#pragma once
6
7#include <cstdint>
8#include <filesystem>
9#include <memory>
10#include <string>
11#include <system_error>
12#include <vector>
13
14namespace pl
15{
18 {
20 enum class Status
21 {
22 Success,
26 Killed,
27 Crashed,
28 Error
29 };
30
32 int32_t exitCode = -1;
33 std::string message;
34
37 [[nodiscard]] auto succeeded() const -> bool
38 {
39 return status == Status::Success;
40 }
41 };
42
43 class PlatformProcess;
44
46 class Process
47 {
48 public:
51
54
56 Process(Process const&) = delete;
57
59 Process& operator=(Process const&) = delete;
60
62 Process(Process&&) = delete;
63
66
71 [[nodiscard]] auto start(std::filesystem::path const& executablePath, std::vector<std::string> const& arguments) -> std::error_code;
72
76 [[nodiscard]] auto terminate() -> std::error_code;
77
83 [[nodiscard]] auto kill(uint32_t const exitCode = 1) -> std::error_code;
84
87 [[nodiscard]] auto wait() -> ProcessResult;
88
89 private:
93 enum class StopRequest
94 {
95 None,
96 Terminate,
97 Kill
98 };
99
100 std::unique_ptr<PlatformProcess> _platformProcess;
101 StopRequest _stopRequest = StopRequest::None;
102 };
103} // namespace pl
Forward declaration.
Definition process.hxx:47
auto wait() -> ProcessResult
~Process()
Destructor.
Process & operator=(Process const &)=delete
Delete copy operation.
Process()
Constructor.
auto kill(uint32_t const exitCode=1) -> std::error_code
auto terminate() -> std::error_code
auto start(std::filesystem::path const &executablePath, std::vector< std::string > const &arguments) -> std::error_code
Process(Process const &)=delete
Delete copy operation.
Process(Process &&)=delete
Delete copy operation.
Process & operator=(Process &&)=delete
Delete copy operation.
Definition error.hxx:10
Describes the outcome of launching and running a process.
Definition process.hxx:18
auto succeeded() const -> bool
Definition process.hxx:37
std::string message
Additional information about a process failure.
Definition process.hxx:33
int32_t exitCode
The exit code returned by the process. A value of -1 indicates that no exit code was available.
Definition process.hxx:32
Status status
The process completion status.
Definition process.hxx:31
Status
The final status of the process.
Definition process.hxx:21
@ Crashed
The process ended unexpectedly (e.g. an unrequested signal or fault), not via terminate()/kill().
@ FailedToStart
The process could not be started.
@ Success
The process ran to completion and exited with code 0.
@ NonZeroExit
The process ran to completion but exited with a non-zero code.
@ Error
An unexpected error occurred while managing the process.
@ Killed
The process was stopped forcibly, via kill().
@ Terminated
The process was asked to stop gracefully, via terminate(), and did.