Another iteration on cooking job

This commit is contained in:
Wojtek Figat
2024-12-05 15:29:24 +01:00
parent 987916cc1c
commit 0ef1220846
3 changed files with 119 additions and 10 deletions

View File

@@ -468,13 +468,12 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings)
if (settings.WaitForEnd)
{
id<NSObject> outputObserver = nil;
id<NSObject> outputObserverError = nil;
if (captureStdOut)
{
NSPipe *stdoutPipe = [NSPipe pipe];
NSPipe* stdoutPipe = [NSPipe pipe];
[task setStandardOutput:stdoutPipe];
[task setStandardError:stdoutPipe];
outputObserver = [[NSNotificationCenter defaultCenter]
addObserverForName: NSFileHandleDataAvailableNotification
object: [stdoutPipe fileHandleForReading]
@@ -498,8 +497,34 @@ int32 MacPlatform::CreateProcess(CreateProcessSettings& settings)
}
}
];
[[stdoutPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
NSPipe *stderrPipe = [NSPipe pipe];
[task setStandardError:stderrPipe];
outputObserverError = [[NSNotificationCenter defaultCenter]
addObserverForName: NSFileHandleDataAvailableNotification
object: [stderrPipe fileHandleForReading]
queue: nil
usingBlock:^(NSNotification* notification)
{
NSData* data = [stderrPipe fileHandleForReading].availableData;
if (data.length)
{
String line((const char*)data.bytes, data.length);
if (settings.SaveOutput)
settings.Output.Add(line.Get(), line.Length());
if (settings.LogOutput)
{
StringView lineView(line);
if (line[line.Length() - 1] == '\n')
lineView = StringView(line.Get(), line.Length() - 1);
Log::Logger::Write(LogType::Error, lineView);
}
[[stderrPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
}
}
];
[[stderrPipe fileHandleForReading] waitForDataInBackgroundAndNotify];
}
String exception;