在NSTask中崩溃

 Liko2502860873 发布于 2022-12-27 12:39

-launch在NSTask 的一次撞车事件中得到了一份报告.

有问题的代码是:

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/bin/zsh"];
if(ignore)
{
    [task setArguments:@[scriptPath, recordingFolder, Argument]];
}
else
{
    [task setArguments:@[scriptPath, recordingFolder]];
}

NSPipe *outPipe = [NSPipe pipe];
[task setStandardOutput:outPipe];

NSPipe *errorPipe = [NSPipe pipe];
[task setStandardError:errorPipe];

[task launch];

scriptPath是应用程序包中包含的脚本.崩溃说:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to set posix_spawn_file_actions for fd -1 at index 0 with errno 9'

可能是什么原因造成的?posix_spawn_file_actions引用了什么文件描述符?这是否意味着可执行脚本错误或者outPipe或errPipe格式不正确?

我相信它指的是posix_spawn函数:https: //developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/posix_spawn.2.html

并且errno 9是EBADF(错误的文件号).

1 个回答
  • 我有一个类似的错误,在我使用下面的命令后,没关系,你可以尝试一下.

    NSFileHandle *file=[outPipe fileHandleForReading];
    [task launch];
    ....//read file.
    //this is the most important.
    [file closeFile];
    

    2022-12-27 12:42 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有