如何从Swift脚本调用外部命令(启动子进程)?
也许类似于Python中的call(["ls", "-l"])
。
发布于 2014-06-20 22:50:59
您仍然可以在Swift中使用NSTask。你的例子应该是这样的。
let task = NSTask()
task.launchPath = "/bin/ls"
task.arguments = ["-l"]
task.launch()
Swift 3+,macOS 10.13+
let task = Process()
task.executableURL = URL(fileURLWithPath: "/bin/ls")
task.arguments = ["-l"]
task.run()
https://stackoverflow.com/questions/24336676
复制相似问题