在哪里可以获得有关使用Swift Process()的信息? [英] Where can I get information on working with Swift Process()?

查看:160
本文介绍了在哪里可以获得有关使用Swift Process()的信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,我希望正确的语法通过Swift运行git clone并完成各种达尔文层的工作,例如运行tar压缩等.

Specifically I would like the correct syntax to run git clone via Swift and do assorted Darwin-layer work like running tar compression etc.

在哪里可以获得Process()的使用信息?

Where can I get some usage info of Process()?

基本上,我想做这样的事情: Process().git克隆... Process().tar ....

Essentially, I want to do something like this: Process().git clone... Process().tar ....

我想方便地与Darwin层一起做基本的事情.

I want to conveniently work with the Darwin layer to do rudimentary stuff.

最好是同步执行此操作,以便在unix层完成其任务后继续处理.

It would be nice to do this synchronously, to continue processing after the unix layer has done its task.

推荐答案

您可以从Process的信息. "nofollow noreferrer"> Apple文档,或者您可以在 GitHub .

You can find out more about Process from Apple's Documentation or you could look at the source code of the open source version on GitHub.

我写了一个简短的示例,说明如何使用Process中要查找的语法编写一些代码.您可以更改该函数接受参数的方式,以便它接受字符串数组而不是特定的命名参数.

I wrote a short example for how you could make some code in the syntax you're looking for from Process. You could make changes to how the function accepts arguments so that it accepts an array of strings instead of specific named arguments.

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: "git@github.com:user/repo.git", path: "path/to/repo")

据我所知,除了字符串以外,没有其他方法可以将参数传递给进程.

As far as I know there's no way to pass the arguments to the process other than as a string.

这篇关于在哪里可以获得有关使用Swift Process()的信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆