gpt4 book ai didi

swift 5.0 : How to fix nw_path_close_fd Failed to close guarded necp fd 4 [9: Bad file descriptor] error

转载 作者:行者123 更新时间:2023-11-30 10:38:12 24 4
gpt4 key购买 nike

问题:
当我在 MacOS 应用程序中运行 Linux 可执行文件时尝试访问 stdout 时,显示错误消息。 stdout 消息仅在稍后的 block 中出现。

上下文:
我想用打印到 XCode 控制台的数据来更新我的用户界面。我尝试了几个教程,但我不断收到 Material 中未涵盖的相同错误消息。

尝试:
我找不到任何解决并实际解决此问题的资源。

错误:

2019-08-09 09:22:21.792908-0700 executable-filename-here[19975:508824] nw_path_close_fd Failed to close guarded necp fd 4 [9: Bad file descriptor]
2019-08-09 09:22:21.811325-0700 executable-filename-here[19976:508830] nw_path_close_fd Failed to close guarded necp fd 4 [9: Bad file descriptor]
2019-08-09 09:22:21.819582-0700 executable-filename-here[19977:508836] nw_path_close_fd Failed to close guarded necp fd 4 [9: Bad file descriptor]
2019-08-09 09:22:21.828539-0700 executable-filename-here[19978:508842] nw_path_close_fd Failed to close guarded necp fd 4 [9: Bad file descriptor]

最佳答案

解决方案:
我在实现有关在 Swift 中拦截 stdout 的教程时找到了这个解决方案。不过,这篇文章没有具体解决这个错误。我注意到错误消失了。显然,dup2 帮助为 inputPipeoutputPipe 设置了正确的文件描述符。

Intercepting stdout in Swift
Mac OS X Developer Tools Manual Page For dup2(2)

import Cocoa

var process = Process()
var inputPipe = Pipe()
var outputPipe = Pipe()

private func runExecutable() {
let url = Bundle.main.url(forResource: "filename_here", withExtension: "")
let arguments = ["argument1", "argument2", "argument3", "etc"]
process.arguments = arguments
process.launchPath = url?.path

// dup2(): Duplicate an existing file descriptor

// Copy STDOUT file descriptor to outputPipe for writing strings back to STDOUT
dup2(STDOUT_FILENO, outputPipe.fileHandleForWriting.fileDescriptor)

// Intercept STDOUT with inputPipe
dup2(inputPipe.fileHandleForWriting.fileDescriptor, STDOUT_FILENO)

process.standardInput = inputPipe
process.standardOutput = outputPipe
try? process.run()

// Restore stdout
freopen("/dev/stdout", "a", stdout)
}

关于 swift 5.0 : How to fix nw_path_close_fd Failed to close guarded necp fd 4 [9: Bad file descriptor] error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57434292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com