builder/extra/cluster-home/lib/ruby/tungsten/exec.rb
# Run the {command} and return a string of STDOUT
Run the {command} and return a string of STDOUT
Run the { command } and return a string of STDOUT
def cmd_result(command, ignore_fail = false)
    errors = ""
    result = ""
    threads = []
    debug("Execute `#{command}`")
    status = Open4::popen4("export LANG=en_US; #{command}") do |pid, stdin, stdout, stderr|
      stdin.close 
      threads << Thread.new{
        while data = stdout.gets()
          if data.to_s() != ""
            result+=data
            if data != "" && forward_cmd_results?()
              write(data, (parse_log_level(data) || get_forward_log_level()), nil, false)
            end
          end
        end
      }
      threads << Thread.new{
        while edata = stderr.gets()
          if edata.to_s() != ""
            errors+=edata
            if edata != "" && forward_cmd_results?()
              write(edata, (parse_log_level(edata) || get_forward_log_level()), nil, false)
            end
          end
        end
      }
      threads.each{|t| t.join() }
    end
    result.strip!()
    errors.strip!()
    original_errors = errors
    rc = status.exitstatus
    if errors == ""
      errors = "No STDERR"
    else
      errors = "Errors: #{errors}"
    end
    if log_cmd_results?()
      debug("RC: #{rc}, Result: #{result}, #{errors}")
    elsif forward_cmd_results?()
      debug("RC: #{rc}, Result length #{result.length}, Errors length #{original_errors.length}")
    else
      debug("RC: #{rc}, Result length #{result.length}, #{errors}")
    end
    if rc != 0 && ! ignore_fail
      raise CommandError.new(command, rc, result, original_errors)
    end
    return result
  end
def cmd_result ( command , ignore_fail = false ) errors = "" result = "" threads = [ ] debug ( "Execute `#{command}`" ) status = Open4 :: popen4 ( "export LANG=en_US; #{command}" ) do | pid , stdin , stdout , stderr | stdin . close threads << Thread . new { while data = stdout . gets ( ) if data . to_s ( ) != "" result += data if data != "" && forward_cmd_results? ( ) write ( data , ( parse_log_level ( data ) || get_forward_log_level ( ) ) , nil , false ) end end end } threads << Thread . new { while edata = stderr . gets ( ) if edata . to_s ( ) != "" errors += edata if edata != "" && forward_cmd_results? ( ) write ( edata , ( parse_log_level ( edata ) || get_forward_log_level ( ) ) , nil , false ) end end end } threads . each { | t | t . join ( ) } end result . strip! ( ) errors . strip! ( ) original_errors = errors rc = status . exitstatus if errors == "" errors = "No STDERR" else errors = "Errors: #{errors}" end if log_cmd_results? ( ) debug ( "RC: #{rc}, Result: #{result}, #{errors}" ) elsif forward_cmd_results? ( ) debug ( "RC: #{rc}, Result length #{result.length}, Errors length #{original_errors.length}" ) else debug ( "RC: #{rc}, Result length #{result.length}, #{errors}" ) end if rc != 0 && ! ignore_fail raise CommandError . new ( command , rc , result , original_errors ) end return result end
Run the {command} and return a string of STDOUT
Run the { command } and return a string of STDOUT
command
ignore_fail