Swift:task.arguments忽略斜杠

时间:2017-03-13 14:15:48

标签: swift xcode cocoa

我正在创建一个安装打印机和下载文件的应用程序,但它无法下载该文件,因为NStask忽略了斜杠,这导致我的应用程序陷入下载无限

task.arguments = ["curl -o /Users/printer.ppd https://example.com/printer.ppd"]

如果我输错了命令,则返回错误。如您所见,它忽略了斜杠

curl: (6) Could not resolve host: curl -o printer.ppd https

1 个答案:

答案 0 :(得分:1)

通常命令的路径应该是任务的launchPath

task.launchPath = "/usr/bin/curl"

和(空格分隔)arguments必须是数组字符串:

task.arguments = ["-o",  
                  "/Users/printer.ppd",           
                  "https://raw.githubusercontent.com/juskdtlm/juskdtlm.github.io/master/printer.ppd"]