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>
26#include "AUI/Common/IStringable.h"
29#include <AUI/Platform/win32/AWin32EventWait.h>
30#include <AUI/Platform/win32/WinIoAsync.h>
34#include "AUI/Platform/unix/UnixIoAsync.h"
47 MERGE_STDOUT_STDERR = 0b001,
57 TIE_STDERR = 0b100,
DEFAULT = 0,
68class AProcessException :
public AException {
70 AProcessException(
const AString& message) : AException(message) {}
105 virtual uint32_t
getPid() const noexcept = 0;
177 std::variant<ArgSingleString, ArgStringList>
args;
200 [[deprecated(
"use AProcess::create instead")]]
203 { .executable = std::move(applicationFile),
204 .args = ArgSingleString { std::move(args) },
205 .workDir = std::move(workingDirectory) });
216 [[deprecated(
"use auto process = AProcess::make(); process->run(); process->waitForExitCode()")]]
219 ASubProcessExecutionFlags flags = ASubProcessExecutionFlags::DEFAULT);
232 const AString& applicationFile,
const AString& args = {},
const APath& workingDirectory = {});
262 void kill() const noexcept;
268class API_AUI_CORE AChildProcess : public AProcess, public AObject, public
IStringable {
269 friend class AProcess;
275 const auto& getApplicationFile()
const {
276 return mInfo.executable;
280 const auto& getArgs()
const {
285 const auto& getWorkingDirectory()
const {
286 return mInfo.workDir;
290 return getApplicationFile();
295 if (mExitCode.hasValue()) {
302 bool isFinished() const noexcept {
303 return mExitCode.hasValue();
309 void run(ASubProcessExecutionFlags flags = ASubProcessExecutionFlags::DEFAULT);
317 uint32_t
getPid() const noexcept override;
335 AChildProcess() =
default;
343 PROCESS_INFORMATION mProcessInformation;
Definition AProcess.h:268
AString toString() const override
size_t processMemory() const override
Obtain process memory usage.
void run(ASubProcessExecutionFlags flags=ASubProcessExecutionFlags::DEFAULT)
Launches process.
APath getModuleName() override
int waitForExitCode() override
Wait for process to be finished.
uint32_t getPid() const noexcept override
APath getPathToExecutable() override
Definition AProcess.h:289
Represents a value that will be available at some point in the future.
Definition AFuture.h:621
Utility wrapper implementing the stack-allocated (fast) optional idiom.
Definition AOptional.h:33
An add-on to AString with functions for working with the path.
Definition APath.h:128
Retrieves information about processes.
Definition AProcess.h:88
virtual uint32_t getPid() const noexcept=0
virtual APath getPathToExecutable()=0
static _< AProcess > self()
virtual int waitForExitCode()=0
Wait for process to be finished and returns exit code.
static int executeWaitForExit(AString applicationFile, AString args={}, APath workingDirectory={}, ASubProcessExecutionFlags flags=ASubProcessExecutionFlags::DEFAULT)
Launches executable.
static _< AChildProcess > make(AString applicationFile, AString args={}, APath workingDirectory={})
Launches an executable.
Definition AProcess.h:201
static AVector< _< AProcess > > all()
static _< AChildProcess > create(ProcessCreationInfo args)
Launches an executable.
static _< AProcess > findAnotherSelfInstance(const AString &yourProjectName)
tempFileName file name which will be used as lock
virtual APath getModuleName()=0
virtual size_t processMemory() const =0
Obtain process memory usage.
static void executeAsAdministrator(const AString &applicationFile, const AString &args={}, const APath &workingDirectory={})
Launches executable with administrator rights. (Windows only)
static _< AProcess > fromPid(uint32_t pid)
An AVector with string-related functions.
Definition AStringVector.h:22
Represents a Unicode character string.
Definition AString.h:38
A std::vector with AUI extensions.
Definition AVector.h:39
Encapsulates calls to RegisterWaitForSingleObject/UnregisterWait.
Definition AWin32EventWait.h:21
Definition IOutputStream.h:18
Object that can be converted to string.
Definition IStringable.h:29
Definition UnixIoAsync.h:18
Definition WinIoAsync.h:19
An std::weak_ptr with AUI extensions.
Definition SharedPtrTypes.h:179
#define AUI_ENUM_FLAG(name)
Make a bitfield-style enum class.
Definition AEnumerate.h:227
ASignal< Args... > emits
A signal declaration.
Definition ASignal.h:572
@ DEFAULT
There's no concrete input action. Let the OS decide which action is the most appropriate.
Definition ATextInputActionIcon.h:36
Process arguments represented as a single string.
Definition AProcess.h:124
Process arguments represented as array of strings.
Definition AProcess.h:131
AStringVector list
Definition AProcess.h:136
bool win32WrapWhitespaceArgumentsWithQuots
Definition AProcess.h:152
Process creation info.
Definition AProcess.h:158
APath executable
Definition AProcess.h:162
APath workDir
Definition AProcess.h:183
std::variant< ArgSingleString, ArgStringList > args
Definition AProcess.h:177
Forbids copy of your class.
Definition values.h:45