UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InteractiveProcess.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/Queue.h"
8#include "CoreTypes.h"
10#include "HAL/PlatformProcess.h"
11#include "HAL/Runnable.h"
12#include "Logging/LogMacros.h"
13#include "Misc/DateTime.h"
14#include "Misc/Timespan.h"
15
16class FRunnableThread;
17
19
26
33
38 : public FRunnable
39{
40public:
41
49 CORE_API FInteractiveProcess(const FString& InURL, const FString& InParams, bool InHidden, bool LongTime = false);
50
59 CORE_API FInteractiveProcess(const FString& InURL, const FString& InParams, const FString& InWorkingDir, bool InHidden, bool LongTime = false);
60
63
70
77 {
78 return ProcessHandle;
79 }
80
86 bool IsRunning() const
87 {
88 return Thread != nullptr;
89 }
90
96 CORE_API bool Launch();
97
104 {
105 return CanceledDelegate;
106 }
107
115 {
116 return CompletedDelegate;
117 }
118
125 {
126 return OutputDelegate;
127 }
128
134 CORE_API void SendWhenReady(const FString &Message);
135
141 CORE_API void SendWhenReady(const TArray<uint8> &Data);
142
148 int GetReturnCode() const
149 {
150 return ReturnCode;
151 }
152
158 void Cancel(bool InKillTree = false)
159 {
160 bCanceling = true;
161 bKillTree = InKillTree;
162 }
163
164 // FRunnable interface
165
166 virtual bool Init() override
167 {
168 return true;
169 }
170
171 CORE_API virtual uint32 Run() override;
172
173 virtual void Stop() override
174 {
175 Cancel();
176 }
177
178 virtual void Exit() override { }
179
180protected:
181
187 CORE_API void ProcessOutput(const FString& Output);
188
193
194private:
195 // Whether the process is being canceled. */
196 bool bCanceling : 1;
197
198 // Whether the window of the process should be hidden. */
199 bool bHidden : 1;
200
201 // Whether to kill the entire process tree when cancelling this process. */
202 bool bKillTree : 1;
203
204 // How many milliseconds should the process sleep */
205 float SleepTime;
206
207 // Holds the URL of the executable to launch. */
208 FString URL;
209
210 // Holds the command line parameters. */
211 FString Params;
212
213 // Holds the URL of the working dir for the process. */
214 FString WorkingDir;
215
216 // Holds the handle to the process. */
217 FProcHandle ProcessHandle;
218
219 // Holds the read pipe of parent process. */
220 void* ReadPipeParent;
221
222 // Holds the write pipe of parent process. */
223 void* WritePipeParent;
224
225 // Holds the read pipe of child process. Should not be used except for testing */
226 void* ReadPipeChild;
227
228 // Holds the write pipe of child process. Should not be used except for testing */
229 void* WritePipeChild;
230
231 // Holds the thread object. */
232 FRunnableThread* Thread;
233
234 // Holds the name of thread */
235 FString ThreadName;
236
237 // Holds the return code. */
238 int ReturnCode;
239
240 // Holds the time at which the process started. */
241 FDateTime StartTime;
242
243 // Holds the time at which the process ended. */
244 FDateTime EndTime;
245
246 // Holds string messages to be written to pipe when ready */
247 TQueue<FString> StringMessagesToProcess;
248
249 // Holds data messages to be written to pipe when ready */
250 TQueue<TArray<uint8>> DataMessagesToProcess;
251
252 // Holds a delegate that is executed when the process has been canceled. */
253 FSimpleDelegate CanceledDelegate;
254
255 // Holds a delegate that is executed when a interactive process completed. */
256 FOnInteractiveProcessCompleted CompletedDelegate;
257
258 // Holds a delegate that is executed when a interactive process produces output. */
259 FOnInteractiveProcessOutput OutputDelegate;
260};
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
Definition DelegateCombinations.h:57
#define DECLARE_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:48
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition InteractiveProcess.h:39
virtual void Stop() override
Definition InteractiveProcess.h:173
CORE_API void SendWhenReady(const FString &Message)
Definition InteractiveProcess.cpp:206
FOnInteractiveProcessOutput & OnOutput()
Definition InteractiveProcess.h:124
CORE_API bool Launch()
Definition InteractiveProcess.cpp:86
int GetReturnCode() const
Definition InteractiveProcess.h:148
FSimpleDelegate & OnCanceled()
Definition InteractiveProcess.h:103
FProcHandle GetProcessHandle() const
Definition InteractiveProcess.h:76
FOnInteractiveProcessCompleted & OnCompleted()
Definition InteractiveProcess.h:114
void Cancel(bool InKillTree=false)
Definition InteractiveProcess.h:158
virtual bool Init() override
Definition InteractiveProcess.h:166
CORE_API void ProcessOutput(const FString &Output)
Definition InteractiveProcess.cpp:133
CORE_API FTimespan GetDuration() const
Definition InteractiveProcess.cpp:76
virtual void Exit() override
Definition InteractiveProcess.h:178
virtual CORE_API uint32 Run() override
Definition InteractiveProcess.cpp:217
CORE_API void SendMessageToProcessIf()
Definition InteractiveProcess.cpp:150
bool IsRunning() const
Definition InteractiveProcess.h:86
CORE_API ~FInteractiveProcess()
Definition InteractiveProcess.cpp:66
Definition RunnableThread.h:20
Definition Runnable.h:20
Definition Array.h:670
Definition Queue.h:48
Definition DateTime.h:76
Definition AndroidPlatformProcess.h:13
Definition Timespan.h:76