def run_command(command, options={})
      timeout = options[:timeout] || 7200

      # default to adding a nice 13 if nothing specified
      nice = if options.key?(:nice)
        (options[:nice] == 'n') ? '' : "nice -n #{options[:nice]} "
      else
        'nice -n 19 '
      end

      echo_return = (options.key?(:echo_return) && !options[:echo_return]) ? '' : '; echo $?'

      cmd = "#{nice}#{command}#{echo_return}"

      logger.info "run_command: #{cmd}"
      begin
        result = Timeout::timeout(timeout) {
          Open3::popen3(cmd) do |i,o,e|
            out_str = ""
            err_str = ""
            i.close # important!
            o.sync = true
            e.sync = true
            o.each{|line|
              out_str << line
              line.chomp!
              logger.debug "stdout:    #{line}"
            }
            e.each { |line|
              err_str << line
              line.chomp!
              logger.debug "stderr:    #{line}"
            }
            return out_str, err_str
          end
        }
      rescue Timeout::Error => toe
        logger.error "run_command:Timeout Error - running command, took longer than #{timeout} seconds to execute: '#{cmd}'"
        raise toe
      end
    end
def run_command(command, options={})
      timeout = options[:timeout] || 7200

      # default to adding a nice 13 if nothing specified
      nice = if options.key?(:nice)
        (options[:nice] == 'n') ? '' : "nice -n #{options[:nice]} "
      else
        'nice -n 19 '
      end

      echo_return = (options.key?(:echo_return) && !options[:echo_return]) ? '' : '; echo $?'

      cmd = "#{nice}#{command}#{echo_return}"

      logger.info "run_command: #{cmd}"
      begin
        result = Timeout::timeout(timeout) {
          Open3::popen3(cmd) do |i,o,e|
            out_str = ""
            err_str = ""
            i.close # important!
            o.sync = true
            e.sync = true
            o.each{|line|
              out_str << line
              line.chomp!
              logger.debug "stdout:    #{line}"
            }
            e.each { |line|
              err_str << line
              line.chomp!
              logger.debug "stderr:    #{line}"
            }
            return out_str, err_str
          end
        }
      rescue Timeout::Error => toe
        logger.error "run_command:Timeout Error - running command, took longer than #{timeout} seconds to execute: '#{cmd}'"
        raise toe
      end
    end
Pass the command to run, and a timeout