- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
问题:
当我在 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
帮助为 inputPipe
和 outputPipe
设置了正确的文件描述符。
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/
正如我不断发现的那样,有各种各样的文件描述符——几乎所有的东西都是围绕文件描述符抽象出来的:常规文件、套接字、信号和计时器(例如)。所有文件描述符都只是整数。 给定一个文件描述符,是否可以知道它是什么
socket fd 长什么样子? 什么是 socket fd ?粗糙的来讲,就是网络 fd,比如我们最常见的 C/S 客户端服务端的编程模式,就是网络通信的一种方式。撇开底层
如果我调用了shutdown(fd,SHUT_RDWR),但没有调用close(fd),会发生什么? inline void CSocket::close() { if (_socket_fd
我有以下结构: struct myfds_for_nic { int fd1; int fd2; int fd3; int fd4; int fd5;
fd 是否有等价于 fseek 的东西?我已经使用 int fds 很长时间了,想使用 fseek...但我知道没有搜索功能。 提前致谢! 最佳答案 参见 POSIX 函数 lseek(2) : SY
我正在使用 Clojure 的 core.logic CLP(FD) 库(core.logic 版本 0.8.3)开发一种简单的方形打包算法。 正方形的表示方式如下: [[[x11 y11] [x12
我正在学习 linux 操作系统,我有一个关于管道的问题。 我想实现一个管道。 所以我定义了int fd[2]; 但是为什么fd[0]是读而fd[1]是写呢? 0代表stdin吗? (我认为是写)而1
我知道进程的pid,需要获取它使用的socketfd,所以在/proc/$pid/中查找fd,例如: $ ls -la /proc/1442/fd | grep socket lrwx------ 1
我正在检查当前 fatrace 的源代码。 调用fanotify获取数据值的主循环如下: res = read (fan_fd, buffer, 4096); ... data
Docker daemon documentation建议大多数设置使用以下 hosts 选项: dockerd -H fd:// 我猜 fd 代表文件描述符。我不明白 fd 如何用于套接字通信。 我
在执行之前:os.read(fd,1024) 我想检查是否会有输出,而不是挂起直到收到输出。由于 fd 是一个 int 对象,我不能这样做: os.fstat(f.fileno()).st_size
我有一个程序 ( https://github.com/raboof/connbeat ) 依赖于 /proc/[pid]/fd/* 来查找给定(网络)inode 的进程。 /proc/[pid]/f
#define STACK_SIZE (1024 * 1024) static char container_stack[STACK_SIZE]; char* const container_args
inotify file in C 我看过下面的代码用来调用 (void) inotify_rm_watch(fd, wd); (void) close(fd); 为什么不呢? inotify_rm_
下面的小 C 程序(我们称之为 pointless): /* pointless.c */ #include #include void main(){ write(STDOUT_FILENO
考虑这个代码示例: #include #include #include int main() { //this file exists and contains data: "ABCD
在父进程中close(fd[1]);, 为什么它会跳过第一个 fd[1](替换为父 STD_OUT)并在子进程中关闭 fd[1]? #define STD_INPUT 0 #define STD_OU
需要使用代理设置运行模拟器,我在命令提示符下使用以下命令来启动模拟器 emulator -avd AVD_for_3_7_WVGA_Nexus_One -http-proxy http://usern
我正在 appcelerator studio 中创建应用程序。在我向其添加 admob 模块之前,它在我的 Android 6 Lenovo a7000 上正常运行。现在我收到这些错误: [ERRO
我不明白必须如何解决以下问题。非常感谢任何帮助学习如何解决这个问题的人! Consider Relation Schema R = {ABCDEFG} with a set of Functional
我是一名优秀的程序员,十分优秀!