My app got crash with error Terminated due to signal 13.
I am creating input pipe and on that line app got crash with above reason.
public func openConsolePipe() {
inputPipe = Pipe()
outputPipe = Pipe()
let pipeReadHandle = inputPipe.fileHandleForReading
dup2(STDOUT_FILENO, outputPipe.fileHandleForWriting.fileDescriptor)
dup2(STDERR_FILENO, outputPipe.fileHandleForWriting.fileDescriptor)
dup2(inputPipe.fileHandleForWriting.fileDescriptor, STDOUT_FILENO)
dup2(inputPipe.fileHandleForWriting.fileDescriptor, STDERR_FILENO)
NotificationCenter.default.addObserver(self, selector: #selector(self.handlePipeNotification), name: FileHandle.readCompletionNotification, object: pipeReadHandle)
pipeReadHandle.readInBackgroundAndNotify()
}
I am following This Link for implement this.
Now above tutorial working fine in regular project.
But I am creating framework of this demo and use it another app code.
At that time app got crash on Line.
dup2(inputPipe.fileHandleForWriting.fileDescriptor, STDERR_FILENO)
This is below method in that I am getting all logs from pipe.
@objc func handlePipeNotification(notification: Notification)
{
inputPipe.fileHandleForReading.readInBackgroundAndNotify()
if let data = notification.userInfo![NSFileHandleNotificationDataItem] as? Data,
let str = String(data: data, encoding: String.Encoding.ascii) {
outputPipe.fileHandleForWriting.write(data)
}
}