Module: RunShell

Defined in:
lib/run_shell.rb

Instance Method Summary collapse

Instance Method Details

#is_windows?Boolean

for Windows-specific tasks.

Returns:

  • (Boolean)


24
25
26
# File 'lib/run_shell.rb', line 24

def is_windows?
  return !!(RUBY_PLATFORM =~ /mswin/)
end

#runshell(cmd, ignoreerrors = false) ⇒ Object

Runs a shell command and pipes output to console.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/run_shell.rb', line 4

def runshell(cmd, ignoreerrors=false)
  puts "+ #{cmd}"
  IO.popen("#{cmd} 2>&1", 'r') do |output|
    output.sync = true
    done = false
    while !done
      begin
        puts output.readline
      rescue EOFError
        done = true
      end
    end
  end

  exitstatus = $?.exitstatus
  fail "SHELL COMMAND FAILED - exit code #{exitstatus}" unless (ignoreerrors || $?.success?)
  return exitstatus
end