使用 Swift 中的参数创建进程?

Creating process with arguments in Swift?

在 Swift 3 中执行过程时出现问题,它不工作,我单击但没有任何反应。

let open = Process()
open.launchPath = "/usr/bin/openssl"
open.arguments = ["openssl enc -aes-256-cbc -d -in \"" + existing.stringValue +
                 "\" -out \"" + new.stringValue + "/" + name.stringValue + "\""]
open.launch()
open.waitUntilExit()

如何在 Swift 中创建带有参数的进程?

使用此函数,您可以将参数作为字符串传递。

func shell(at: String, _ args: String) {
    let task = Process()
    task.launchPath = at
    task.arguments = ["-c", args]

    let pipeStandard = Pipe()
    task.standardOutput = pipeStandard
    task.launch()

    let dataStandard = pipeStandard.fileHandleForReading.readDataToEndOfFile()
    let outputStandard = String(data: dataStandard, encoding: String.Encoding.utf8)!
    if outputStandard.count > 0  {
        let lastIndexStandard = outputStandard.index(before: outputStandard.endIndex)
        print(String(outputStandard[outputStandard.startIndex ..< lastIndexStandard]))
    }
    task.waitUntilExit()
}