[英]Creating process with arguments in Swift?
Problem with doing process in Swift 3, It's not working, I click and nothing is happening. 在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()
How do I create a process with arguments in Swift? 如何在Swift中使用参数创建进程?
With this function, you can pass the arguments as a string. 使用此功能,您可以将参数作为字符串传递。
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()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.