具体来说,我希望通过Swift运行git clone的正确语法,并执行各种Darwin层工作,如运行tar压缩等。
我在哪里可以获得Process()的一些使用信息?
基本上,我想做这样的事情:Process()。git clone ... Process()。tar ....
我想方便地使用达尔文层来做基本的事情。
同步这样做会很好,在unix层完成任务后继续处理。
你可以从Process
找到更多关于Apple's Documentation的内容,或者谈谈GitHub的开源版本的源代码。
我写了一个简短的例子,说明如何在Process
中寻找语法代码。您可以更改函数如何接受参数,以便它接受字符串数组而不是特定的命名参数。
extension Process {
private static let gitExecURL = URL(fileURLWithPath: "/usr/bin/git")
func clone(repo: String, path: String) throws {
executableURL = Process.gitExecURL
arguments = ["clone", repo, path]
try run()
}
}
try! Process().clone(repo: "[email protected]:user/repo.git", path: "path/to/repo")
据我所知,除了作为字符串之外,没有办法将参数传递给进程。