mugyu
4/6/2014 - 12:06 PM

実行した環境の OS が Windows?

実行した環境の OS が Windows?

# 実行した環境の OS が Windows?
# Windows9* 以前の Windows でも判定できる
# 頑張れば MS-DOS も判定するようにできる
def os_is_Windows?
  begin
    output = `ver`
    return false if output.nil?
    output.match("Windows") ? true : false
  rescue SystemCallError
    return false
  end
end

# WindowsXP 以前の公式サポートが切れてる現状では
# コッチの方がコマンドを実行しないからいいかも
def os_is_Windows?
  ENV['OS'].match("Windows") ? true : false
end