void FWindowsPlatformProcess::CloseProc(FProcHandle & ProcessHandle) { if (ProcessHandle.IsValid()) { ::CloseHandle(ProcessHandle.Get()); ProcessHandle.Reset(); } }
void FLinuxPlatformProcess::CloseProc(FProcHandle & ProcessHandle) { // dispose of both handle and process info FProcState * ProcInfo = ProcessHandle.GetProcessInfo(); ProcessHandle.Reset(); delete ProcInfo; }
bool FFeedbackContextMarkup::PipeProcessOutput(const FText& Description, const FString& URL, const FString& Params, FFeedbackContext* Warn, int32* OutExitCode) { bool bRes; // Create a read and write pipe for the child process void* PipeRead = NULL; void* PipeWrite = NULL; verify(FPlatformProcess::CreatePipe(PipeRead, PipeWrite)); // Start the slow task Warn->BeginSlowTask(Description, true, true); // Create the process FProcHandle ProcessHandle = FPlatformProcess::CreateProc(*URL, *Params, false, true, true, NULL, 0, NULL, PipeWrite); if(ProcessHandle.IsValid()) { FString BufferedText; for(bool bProcessFinished = false; !bProcessFinished; ) { bProcessFinished = FPlatformProcess::GetProcReturnCode(ProcessHandle, OutExitCode); if(!bProcessFinished && Warn->ReceivedUserCancel()) { FPlatformProcess::TerminateProc(ProcessHandle); bProcessFinished = true; } BufferedText += FPlatformProcess::ReadPipe(PipeRead); int32 EndOfLineIdx; while(BufferedText.FindChar('\n', EndOfLineIdx)) { FString Line = BufferedText.Left(EndOfLineIdx); Line.RemoveFromEnd(TEXT("\r")); if(!ParseCommand(Line, Warn)) { Warn->Log(*Line); } BufferedText = BufferedText.Mid(EndOfLineIdx + 1); } FPlatformProcess::Sleep(0.1f); } ProcessHandle.Reset(); bRes = true; } else { Warn->Logf(ELogVerbosity::Error, TEXT("Couldn't create process '%s'"), *URL); bRes = false; } // Finish the slow task Warn->EndSlowTask(); // Close the pipes FPlatformProcess::ClosePipe(0, PipeRead); FPlatformProcess::ClosePipe(0, PipeWrite); return bRes; }