From deac960e10cad17e614ae3ff49dcd256af36d02b Mon Sep 17 00:00:00 2001 From: naturecodevoid <44983869+naturecodevoid@users.noreply.github.com> Date: Sun, 19 Feb 2023 09:54:56 -0800 Subject: [PATCH] Revert OutputCapturer changes since Fabian already added the fix --- AltStore/Manager/OutputCapturer.swift | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/AltStore/Manager/OutputCapturer.swift b/AltStore/Manager/OutputCapturer.swift index 8c59e28c..e0af952d 100644 --- a/AltStore/Manager/OutputCapturer.swift +++ b/AltStore/Manager/OutputCapturer.swift @@ -15,41 +15,42 @@ class OutputCapturer { private let consoleManager = LCManager.shared - private var stdoutPipe = Pipe() - private var stderrPipe = Pipe() + private var inputPipe = Pipe() + private var errorPipe = Pipe() private var outputPipe = Pipe() private init() { // Setup pipe file handlers - self.stdoutPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in + self.inputPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in self?.handle(data: fileHandle.availableData) } - self.stderrPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in + self.errorPipe.fileHandleForReading.readabilityHandler = { [weak self] fileHandle in self?.handle(data: fileHandle.availableData, isError: true) } - - // Keep output in STDOUT without causing infinite loop + + // Keep STDOUT dup2(STDOUT_FILENO, self.outputPipe.fileHandleForWriting.fileDescriptor) // Intercept STDOUT and STDERR - dup2(self.stdoutPipe.fileHandleForWriting.fileDescriptor, STDOUT_FILENO) - dup2(self.stderrPipe.fileHandleForWriting.fileDescriptor, STDERR_FILENO) + dup2(self.inputPipe.fileHandleForWriting.fileDescriptor, STDOUT_FILENO) + dup2(self.errorPipe.fileHandleForWriting.fileDescriptor, STDERR_FILENO) } deinit { - try? self.stdoutPipe.fileHandleForReading.close() - try? self.stderrPipe.fileHandleForReading.close() + try? self.inputPipe.fileHandleForReading.close() + try? self.errorPipe.fileHandleForReading.close() } private func handle(data: Data, isError: Bool = false) { + // Write output to STDOUT + self.outputPipe.fileHandleForWriting.write(data) + guard let string = String(data: data, encoding: .utf8) else { return } DispatchQueue.main.async { self.consoleManager.print(string) - // put data back into STDOUT so it appears in Xcode/idevicedebug run - self.outputPipe.fileHandleForWriting.write(data) // this might not need to be async } } }