我一直在使用以下命令在OS X中启动默认浏览器:
system('open', url)
在升级到优胜美地之前,它一直运行良好。现在,当尝试打开各种URL时,我经常收到此消息:
LSOpenURLsWithRole() failed with error -1712 for the URL http://blah.com
但有时该URL会起作用。我可以尝试一次,它会起作用,而另一种可能就不会。非常不可预测。
我已经尝试了所有这些方法:
system("open #{url}")
`open #{url}`
Launchy.open(url, debug: true)
Launchy.open( "#{ url }" ) do |exception|
puts "Attempted to open #{url} and failed because #{exception}"
end
但是它们都表现出相同的行为。一次会打开多个URL,如下所示:
urls.each do |url|
system("open #{url}")
end
如何使用ruby在OS X的浏览器中始终打开特定的URL?
好像您同时在浏览器中添加了太多网址。
使用sleep
似乎可以正常工作。
15.times {|i| `open http://google.com?q=#{i}` }
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=5.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=6.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=12.
# LSOpenURLsWithRole() failed with error -1712 for the URL http://google.com?q=14.
# => 15
15.times {|i| sleep(0.2); `open http://google.com?q=#{i}` }
# => 15
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句