在终端这有效:
/usr/bin/curl --connect-timeout 10 --max-time 60 https://en.wikipedia.org/wiki/The_Beatles -o /Users/username/Desktop/wikiData
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 909k 100 909k 0 0 2025k 0 --:--:-- --:--:-- --:--:-- 2025k
但在 Xcode 中,这不会:
let task = Process()
let pipe = Pipe()
task.launchPath = "/usr/bin/curl"
task.arguments = ["--connect-timeout","10","--max-time","60","en.wikipedia.org/wiki/The_Beatles","-o","/Users/username/Desktop/wikiData"]
task.standardOutput = pipe
task.launch()
task.waitUntilExit()
我明白了:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
Warning: Failed to create the file /Users/username/Desktop/wikiData:
Warning: Operation not permitted
curl: (23) Failed writing received data to disk/application
如何授予 curl 写入磁盘的权限?在沙箱中,我检查了“网络传入/传出”以便能够与维基百科交谈,并设置“文件访问/用户选择的文件/读/写”,但这似乎不适用于 curl。如果我离开“-o ...”,我不会出错。但我似乎也没有得到任何数据。想法?谢谢。