gpt4 book ai didi

ruby - 在 Ruby 中使用 URL 打开浏览器

转载 作者:数据小太阳 更新时间:2023-10-29 08:37:30 25 4
gpt4 key购买 nike

我一直在使用以下命令启动 OS X 中的默认浏览器:

system('open', url)

在升级到 Yosemite 之前一直运行良好。现在,我在尝试打开各种 URLS 时经常收到此消息:

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?

最佳答案

看起来您同时使用太多 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

关于ruby - 在 Ruby 中使用 URL 打开浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27512820/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com