【发布时间】:2020-06-13 01:09:21
【问题描述】:
我想运行一个 git 命令,然后从 macOS 应用程序启动 Xcode。
但我目前在第一步被阻止:运行 git 命令
我使用Process、NSWorkspace.shared.openApplication 尝试了很多代码,但仍然被阻止。你可以在这里看到我的最后一次尝试。
@discardableResult
func shell(_ app: String, _ args: String...) -> Int32 {
let task = Process()
task.launchPath = "/usr/bin/\(app)"
task.arguments = args
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
shell("git", "clone https://github.com/user/repo.git")
但是抛出了一个错误:
git: 'clone https://github.com/user/repo.git' 不是 git 命令。请参阅“git --help”。
我错了吗?这是正确的做法吗? 我需要授予权限或类似的东西吗?
【问题讨论】:
-
单独的参数:
shell("git", "clone", "https://github.com/user/repo.git")