Class: Applyrics::Command
- Inherits:
-
Object
- Object
- Applyrics::Command
- Defined in:
- lib/applyrics/command.rb
Class Method Summary collapse
Class Method Details
.execute(command, show_output = true) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/applyrics/command.rb', line 22 def execute(command, show_output=true) output = [] command = command.join(" ") if command.kind_of?(Array) begin PTY.spawn(command) do |stdin, stdout, pid| stdin.each do |l| line = l.strip output << line #next unless print_all # Prefix the current line with a string #prefix.each do |element| # line = element[:prefix] + line if element[:block] && element[:block].call(line) #end puts line unless !show_output end Process.wait(pid) end rescue Errno::EIO rescue => ex puts "Error".red puts ex end # Exit status for build command, should be 0 if build succeeded status = $?.exitstatus if status != 0 o = output.join("\n") puts o end return output.join("\n") end |
.which(command) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/applyrics/command.rb', line 9 def which(command) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| cmd_path = File.join(path, "#{command}#{ext}") return cmd_path if File.executable?(cmd_path) && !File.directory?(cmd_path) end end return nil end |