Method: Mixin::Shell#run

Defined in:
lib/fox/interface/thor/mixin/shell.rb

#run(command, regexp = nil) ⇒ String

Returns empty string if command not found or other problem, otherwise result of command.

Parameters:

  • command (String)

    The command to run

  • regexp (RegExp) (defaults to: nil)

    Optional regular expression used for matching output

Returns:

  • (String)

    Returns empty string if command not found or other problem, otherwise result of command.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fox/interface/thor/mixin/shell.rb', line 41

def run command, regexp = nil

  result      = ''

  begin
    if( regexp.nil? )
      result  = execute( command ).strip
    else
      raise ArgumentError, 'Regular Expression input needs to be of type Regexp' unless( regexp.is_a?( Regexp ) )

      result  = execute( command ).andand.send( :match, regexp ).andand.send( :to_s ).strip
    end

  rescue Exception => e
    say '(EE) ' + e.message, :red
    result    = ''
  end

  return result
end