【发布时间】:2017-11-22 01:57:16
【问题描述】:
使用 Swift Process 运行 MySQL 还原转储文件时遇到问题。
let command = "/usr/local/bin/mysql -h theHost -P 3306 -u root -pTheInlinePassword example_database < dumpFile.sql"
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = command.components(separatedBy: " ")
task.launch()
问题是进程不理解标准输入<。我怎样才能像这样使用标准输入运行命令?谢谢。
更新:
let task = Process()
task.launchPath = "/usr/local/bin/mysql"
task.arguments = ["-h", "theHost", "-P", "3306", "-u", "root", "-pTheInLinePassword", "example_data"]
task.standardInput = try! FileHandle(forReadingFrom: filePath!)
task.launch()
我尝试了下面的代码。这对我有用
【问题讨论】: