【问题标题】:'NSInternalInconsistencyException', reason: 'Couldn't posix_spawn: error 13' Swift'NSInternalInconsistencyException',原因:'不能 posix_spawn:错误 13' Swift
【发布时间】:2019-06-17 07:55:15
【问题描述】:

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

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

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

基本上,我有一个NSTask.h file,它允许我将 NSTask 与 Swift 一起使用。

所以,为了启动一个任务,我做了以下函数:

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'

我可以做些什么来修复这个错误?

提前致谢。

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

【问题讨论】:

    标签: ios swift jailbreak nstask


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-25
      相关资源
      最近更新 更多