Py学习  »  Git

如何在Swift中从macOS应用程序运行git命令?

Kevin Machado • 4 年前 • 917 次点击  

我想运行一个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:'克隆 https://github.com/user/repo.git '不是git命令。请参阅“git--help”。

我需要授予权限吗?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/55452
 
917 次点击  
文章 [ 1 ]  |  最新文章 4 年前
Code-Apprentice
Reply   •   1 楼
Code-Apprentice    4 年前

你在向 git "clone https://github.com/user/repo.git" . 相反,您需要将“clone”和URL作为单独的参数传递:

shell("git", "clone", "https://github.com/user/repo.git")