program tip

Ruby에서 기본 브라우저 열기

radiobox 2021. 1. 5. 07:54
반응형

Ruby에서 기본 브라우저 열기


Python에서는 다음을 수행 할 수 있습니다.

import webbrowser
webbrowser.open_new("http://example.com/")

기본 브라우저에서 전달 된 URL이 열립니다.

루비에 상응하는 것이 있습니까?


크로스 플랫폼 솔루션 :

먼저 Launchy gem을 설치합니다 .

$ gem install launchy

그런 다음 다음을 실행할 수 있습니다.

require 'launchy'

Launchy.open("http://stackoverflow.com")

Mac 전용 솔루션 :

system("open", "http://stackoverflow.com/")

또는

`open http://stackoverflow.com/`

이것은 대부분의 플랫폼에서 작동합니다.

link = "Insert desired link location here"
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
  system "start #{link}"
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
  system "open #{link}"
elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
  system "xdg-open #{link}"
end

가장 간단한 Win 솔루션 :

`http://www.example.com 시작`

Linux 전용 솔루션

system("xdg-open", "http://stackoverflow.com/")

이것은 또한 작동합니다 :

system("start #{link}")

Windows 전용 솔루션 :

require 'win32ole'
shell = WIN32OLE.new('Shell.Application')
shell.ShellExecute(...)

MSDN에서 쉘 실행


Windows이고 IE 인 경우 다음을 시도하십시오. http://rubyonwindows.blogspot.com/search/label/watir 또한 Selenium ruby를 확인 하십시오 . http://selenium.rubyforge.org/getting-started.html

HTH

참조 URL : https://stackoverflow.com/questions/152699/open-the-default-browser-in-ruby

반응형