반응형
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(...)
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
반응형
'program tip' 카테고리의 다른 글
파일 크기에 대한 하드 링크 계산? (0) | 2021.01.05 |
---|---|
RecyclerView가 onCreateViewHolder 또는 onBindView를 호출하지 않습니다. (0) | 2021.01.05 |
Oracle의 to_char () 함수가 공백을 추가하는 이유는 무엇입니까? (0) | 2021.01.05 |
curl_init () 함수가 작동하지 않습니다. (0) | 2021.01.05 |
JavaScript에서 문자열의 마지막 부분을 얻는 방법은 무엇입니까? (0) | 2021.01.05 |