我正在尝试从我的应用程序中调用终端命令,特别是 git 命令。
在最简单的情况下,我们只是说我想打电话git status
对于给定的目录。
我的应用程序的目的是对 git 进行包装,以提供 git 工具的使用,而无需用户与命令行进行任何直接交互(想想 Sourcetree)。
当尝试拨打电话时git status
使用普通方法在 Swift 中运行命令
func shell(launchPath: String, arguments: [String]) -> String {
let task = Process()
task.launchPath = launchPath
task.arguments = arguments
let pipe = Pipe()
task.standardOutput = pipe
task.launch()
let data = pipe.fileHandleForReading.readDataToEndOfFile()
let output: String = String(data: data, encoding: String.Encoding.utf8)!
return output
}
print(shell(launchPath: "/usr/bin/git", arguments: ["status"]))
我(可以理解)收到错误xcrun: error: cannot be used within an App Sandbox.
我可以通过禁用安全设置和应用程序沙箱来解决这个问题.entitlements
文件,但这显然不是一个更好的做法。
有没有办法允许我的应用程序被授予使用/usr/bin/git
在某些目录中?
非常感谢。
None
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)