18#include <AUI/IO/APath.h>
19#include <AUI/Common/AException.h>
20#include <AUI/Common/AVector.h>
21#include <AUI/Common/AObject.h>
22#include <AUI/Common/ASignal.h>
23#include <AUI/IO/IInputStream.h>
24#include <AUI/IO/IOutputStream.h>
25#include <AUI/Thread/AFuture.h>
28#include <AUI/Platform/win32/AWin32EventWait.h>
29#include <AUI/Platform/win32/WinIoAsync.h>
33#include "AUI/Platform/unix/UnixIoAsync.h"
42AUI_ENUM_FLAG(ASubProcessExecutionFlags) {
46 MERGE_STDOUT_STDERR = 0b001,
57class AProcessException :
public AException {
59 AProcessException(
const AString& message) : AException(message) {}
82 virtual uint32_t
getPid() const noexcept = 0;
152 std::variant<ArgSingleString, ArgStringList>
args;
175 [[deprecated(
"use AProcess::create instead")]]
178 { .executable = std::move(applicationFile),
179 .args = ArgSingleString { std::move(args) },
180 .workDir = std::move(workingDirectory) });
191 [[deprecated(
"use auto process = AProcess::make(); process->run(); process->waitForExitCode()")]]
192 static int executeWaitForExit(
193 AString applicationFile, AString args = {}, APath workingDirectory = {},
194 ASubProcessExecutionFlags flags = ASubProcessExecutionFlags::DEFAULT);
205 static void executeAsAdministrator(
206 const AString& applicationFile,
const AString& args = {},
const APath& workingDirectory = {});
213 static AVector<_<AProcess>> all();
218 static _<AProcess> self();
224 static _<AProcess> findAnotherSelfInstance(
const AString& yourProjectName);
229 static _<AProcess> fromPid(uint32_t pid);
231 void kill() const noexcept;
237class API_AUI_CORE AChildProcess : public AProcess, public AObject {
238 friend class AProcess;
244 const auto& getApplicationFile()
const {
245 return mInfo.executable;
249 const auto& getArgs()
const {
254 const auto& getWorkingDirectory()
const {
255 return mInfo.workDir;
259 return getApplicationFile();
264 if (mExitCode.hasValue()) {
271 bool isFinished() const noexcept {
272 return mExitCode.hasValue();
278 void run(ASubProcessExecutionFlags flags = ASubProcessExecutionFlags::DEFAULT);
284 int waitForExitCode()
override;
286 uint32_t getPid() const noexcept override;
288 size_t processMemory() const override;
290 APath getModuleName() override;
293 const _<IOutputStream>& getStdInStream()
const {
303 AChildProcess() =
default;
304 ProcessCreationInfo mInfo;
306 _<IOutputStream> mStdInStream;
309 AFuture<int> mExitCode;
311 PROCESS_INFORMATION mProcessInformation;
312 AWin32EventWait mExitEvent;
313 WinIoAsync mStdoutAsync;
316 _<AThread> mWatchdog;
317 UnixIoAsync mStdoutAsync;
Definition AProcess.h:237
APath getPathToExecutable() override
Definition AProcess.h:258
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:32
An add-on to AString with functions for working with the path.
Definition APath.h:107
virtual uint32_t getPid() const noexcept=0
virtual APath getPathToExecutable()=0
virtual int waitForExitCode()=0
Wait for process to be finished and returns exit code.
static _< AChildProcess > make(AString applicationFile, AString args={}, APath workingDirectory={})
Launches an executable.
Definition AProcess.h:176
virtual APath getModuleName()=0
virtual size_t processMemory() const =0
Obtain process memory usage.
static _< AChildProcess > create(ProcessCreationInfo args)
Launches an executable.
Definition AProcess.cpp:27
An AVector with string-related functions.
Definition AStringVector.h:22
Represents a Unicode character string.
Definition AString.h:37
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:178
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:348
@ DEFAULT
There's no concrete input action. Let the OS decide which action is the most appropriate.
Definition ATextInputActionIcon.h:39
Process arguments represented as a single string.
Definition AProcess.h:101
Process arguments represented as array of strings.
Definition AProcess.h:108
AStringVector list
Definition AProcess.h:113
bool win32WrapWhitespaceArgumentsWithQuots
Definition AProcess.h:128
Process creation info.
Definition AProcess.h:134
APath executable
Definition AProcess.h:138
APath workDir
Definition AProcess.h:158
std::variant< ArgSingleString, ArgStringList > args
Definition AProcess.h:152
Forbids copy of your class.
Definition values.h:40