UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MonitoredProcess.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "CoreTypes.h"
10#include "HAL/Runnable.h"
11#include "Misc/DateTime.h"
13#include "Misc/Timespan.h"
14
15class FRunnableThread;
16
23
24
30
31
32
37{
38public:
39
48 CORE_API FMonitoredProcess( const FString& InURL, const FString& InParams, bool InHidden, bool InCreatePipes = true );
49
59 CORE_API FMonitoredProcess( const FString& InURL, const FString& InParams, const FString& InWorkingDir, bool InHidden, bool InCreatePipes = true );
60
63
64public:
65
71 void Cancel( bool InKillTree = false )
72 {
73 KillTree = InKillTree;
74 Canceling = true;
75 }
76
82 CORE_API FTimespan GetDuration() const;
83
90 {
91 return ProcessHandle;
92 }
93
97 FString GetCommandline() const
98 {
99 return FString::Printf(TEXT("%s %s"), *URL, *Params);
100 }
101
107 CORE_API bool Update();
108
110 CORE_API virtual bool Launch();
111
118 {
119 SleepInterval = InSleepInterval;
120 }
121
122public:
123
130 {
131 return CanceledDelegate;
132 }
133
140 {
141 return CompletedDelegate;
142 }
143
150 {
151 return OutputDelegate;
152 }
153
159 CORE_API int GetReturnCode() const;
160
165 CORE_API const FString& GetFullOutputWithoutDelegate() const;
166
167public:
168
169 // FRunnable interface
170
171 virtual bool Init() override
172 {
173 return true;
174 }
175
176 CORE_API virtual uint32 Run() override;
177
178 virtual void Stop() override
179 {
180 Cancel();
181 }
182
183 virtual void Exit() override { }
184
186 {
187 return this;
188 }
189
190protected:
191
195 CORE_API void Tick() override;
196
202 CORE_API void ProcessOutput( const FString& Output );
203
204protected:
205 CORE_API void TickInternal();
206
207
208 // Whether the process is being canceled. */
209 TAtomic<bool> Canceling = false;
210
211 // Holds the time at which the process ended. */
213
214 // Whether the window of the process should be hidden. */
215 bool Hidden = false;
216
217 // Whether to kill the entire process tree when cancelling this process. */
218 TAtomic<bool> KillTree = false;
219
220 // Holds the command line parameters. */
221 FString Params;
222
223 // Holds the handle to the process. */
225
226 // Holds the non-inheritable read end of stdout pipe. */
227 void* ReadPipe = nullptr;
228
229 // Holds the return code. */
230 TAtomic<int> ReturnCode = 0;
231
232 // Holds the time at which the process started. */
233 TAtomic<FDateTime> StartTime { 0 };
234
235 // Holds the monitoring thread object. */
237
238 // Is the thread running?
240
241 // Holds the URL of the executable to launch. */
242 FString URL;
243
244 // Holds the URL of the working dir for the process. */
245 FString WorkingDir;
246
247 // Holds the inheritable write end of stdout pipe. */
248 void* WritePipe = nullptr;
249
250 // Holds if we should create pipes
251 bool bCreatePipes = false;
252
253 // Sleep interval to use
254 float SleepInterval = 0.01f;
255
256 // Buffered output text which does not contain a newline
258
259protected:
260
261 // Holds a delegate that is executed when the process has been canceled. */
263
264 // Holds a delegate that is executed when a monitored process completed. */
266
267 // Holds a delegate that is executed when a monitored process produces output. */
269};
270
271
273{
274public:
278 static CORE_API FString GetUATPath();
279
280public:
282
287 CORE_API virtual bool Launch() override;
288
295 {
296 return LaunchFailedDelegate;
297 }
298
299
300private:
301
302 CORE_API bool LaunchNext();
303 CORE_API bool LaunchInternal();
304 static CORE_API void CancelQueue();
305
306 // When this one completes, run the next in line
307 FSerializedUATProcess* NextProcessToRun = nullptr;
308
309 // Holds a delegate that is executed when the process fails to launch (delayed, in a thread). Used in place of the return value
310 // of Launch in the parent class, since it's async
311 FSimpleDelegate LaunchFailedDelegate;
312
313 static CORE_API FCriticalSection Serializer;
314 static CORE_API bool bHasSucceededOnce;
315 static CORE_API FSerializedUATProcess* HeadProcess;
316};
#define TEXT(x)
Definition Platform.h:1272
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
UE::FPlatformRecursiveMutex FCriticalSection
Definition CriticalSection.h:53
#define DECLARE_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:48
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition MonitoredProcess.h:37
void SetSleepInterval(float InSleepInterval)
Definition MonitoredProcess.h:117
virtual bool Init() override
Definition MonitoredProcess.h:171
virtual void Stop() override
Definition MonitoredProcess.h:178
FOnMonitoredProcessOutput & OnOutput()
Definition MonitoredProcess.h:149
virtual FSingleThreadRunnable * GetSingleThreadInterface() override
Definition MonitoredProcess.h:185
FOnMonitoredProcessOutput OutputDelegate
Definition MonitoredProcess.h:268
FOnMonitoredProcessCompleted & OnCompleted()
Definition MonitoredProcess.h:139
FString Params
Definition MonitoredProcess.h:221
FSimpleDelegate & OnCanceled()
Definition MonitoredProcess.h:129
FString URL
Definition MonitoredProcess.h:242
FString WorkingDir
Definition MonitoredProcess.h:245
FSimpleDelegate CanceledDelegate
Definition MonitoredProcess.h:262
FString OutputBuffer
Definition MonitoredProcess.h:257
TAtomic< bool > bIsRunning
Definition MonitoredProcess.h:239
TAtomic< FDateTime > EndTime
Definition MonitoredProcess.h:212
virtual void Exit() override
Definition MonitoredProcess.h:183
FOnMonitoredProcessCompleted CompletedDelegate
Definition MonitoredProcess.h:265
FProcHandle ProcessHandle
Definition MonitoredProcess.h:224
void Cancel(bool InKillTree=false)
Definition MonitoredProcess.h:71
FString GetCommandline() const
Definition MonitoredProcess.h:97
FProcHandle GetProcessHandle() const
Definition MonitoredProcess.h:89
Definition RunnableThread.h:20
Definition Runnable.h:20
Definition MonitoredProcess.h:273
virtual CORE_API bool Launch() override
Definition MonitoredProcess.cpp:292
static CORE_API FString GetUATPath()
Definition MonitoredProcess.cpp:382
FSimpleDelegate & OnLaunchFailed()
Definition MonitoredProcess.h:294
Definition SingleThreadRunnable.h:12
Definition Launch.Build.cs:10
Definition Atomic.h:538
Definition AndroidPlatformProcess.h:13
Definition Timespan.h:76