Module: RunJS::OS

Extended by:
Encoding
Defined in:
lib/runjs/os.rb

Class Method Summary collapse

Methods included from Encoding

encode

Class Method Details

.popen(cmd, options = {}) ⇒ Object



33
34
35
36
37
# File 'lib/runjs/os.rb', line 33

def self.popen(cmd, options = {})
  cmd = shell_escape(cmd) << ' 2>&1'
  result = IO.popen(cmd) { |io| io.read }
  encode(result, 'UTF-8', options[:external_encoding])
end

.success?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/runjs/os.rb', line 50

def self.success?
  $?.success?
end

.which(cmd) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/runjs/os.rb', line 9

def self.which(cmd)
  cmd += extension(cmd)
  return cmd if executable?(cmd)
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    path = File.join(path, cmd)
    return path if executable?(path)
  end
  nil
end

.write_tempfile(text, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/runjs/os.rb', line 19

def self.write_tempfile(text, &block)
  file = Tempfile.new(['runjs', '.js'])
  file.binmode  # Required on Windows when writing UTF-16
  file.write(text)
  file.close
  yield file.path
ensure
  file.close!
end