gpt4 book ai didi

ios - 'NSInternalInconsistencyException',原因 : 'Couldn' t posix_spawn: error 13' Swift

转载 作者:行者123 更新时间:2023-11-28 05:41:16 27 4
gpt4 key购买 nike

我正在使用 Swift 为运行 iOS 12 的越狱设备制作一个 iOS 应用。

最近我做了一个问题,我自己回答了一个问题,我在其中问了一个run command line tasks with Swift in iOS的方法。 .

但如您所见,我还没有完成,因为我可以使用 NSTask,但它在运行应用程序时崩溃了。

基本上,我有一个 NSTask.h file这让我可以在 Swift 中使用 NSTask。

因此,为了启动任务,我编写了以下函数:

func task(launchPath: String, arguments: String...) {
let task = NSTask.init()
task?.setLaunchPath(launchPath)
task?.arguments = arguments

// Create a Pipe and make the task
// put all the output there
let pipe = Pipe()
task?.standardOutput = pipe

// Launch the task
task?.launch()
task?.waitUntilExit()
}

然后像这样调用函数:

task(launchPath: "/usr/bin", arguments: "git clone https://github.com/lz4/lz4.git")

问题是当我运行应用程序时,它崩溃并打印出以下错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't posix_spawn: error 13'

我该怎么做才能解决这个错误?

提前致谢。

编辑:顺便说一下,我忘了提到我使用桥接 header 访问NSTask.h 文件。

最佳答案

启动路径必须是可执行文件的完整路径,而不是包含可执行文件的目录。此外,命令参数应作为单独的参数提供,而不是作为一个字符串提供。 (请注意,在启动进程之前不涉及解析命令和分隔参数的 shell。)因此调用应该类似于

task(launchPath: "/usr/bin/git", arguments: "clone", "https://github.com/lz4/lz4.git")

关于ios - 'NSInternalInconsistencyException',原因 : 'Couldn' t posix_spawn: error 13' Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56626997/

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