class ShellResult
This class holds the results from an executed shell command.
Attributes
err[R]
out[R]
Public Class Methods
cleanup(command, path, out)
click to toggle source
Cleans up the output string, if necessary.
Input¶ ↑
- command : String
-
The command that was called.
- path : String
-
The current directory when the command was run.
- out : String
-
The output (on stdout) from the command.
Output¶ ↑
- String
-
A string that has been cleaned up.
Notes¶ ↑
This is primarily for Windows since cmd adds a bunch of garbage to the output.
# File lib/execute_shell/shell_result.rb, line 81 def self.cleanup(command, path, out) case Platform::IMPL when :mingw # Remove all the extra stuff that the cmd prompt adds. out.gsub!(/\n\n#{path.gsub(%r[/], '\\\\\\')}>\Z/, '') # replace contains the command line prompt # and the command up to the first space. replace = path.gsub(%r[/], '\\\\\\') replace += '>' replace += command[0..(command.index(/ /) || 0) - 1] # Remove the header portion of the text. # This includes the Microsoft 'banner' text # that consumes the first two lines. out = out.gsub(/\A.+#{replace}.*?$/m, '').strip end return out end
new(out, err)
click to toggle source
Constructor
Input¶ ↑
- out : String
-
The output from stdout.
- err : String
-
The output from stderr.
Output¶ ↑
ShellResult
-
A new
ShellResult
object.
# File lib/execute_shell/shell_result.rb, line 43 def initialize(out, err) @out = out @err = err end
Public Instance Methods
success?()
click to toggle source
Indicates whether the command was executed successfully.
The output is based on the contents of the err attribute.
Output¶ ↑
- Boolean
-
Indicates whether the command was successful.
Examples¶ ↑
ShellResult.new('a', nil).success? #=> true ShellResult.new('a', '').success? #=> true ShellResult.new('a', ' ').success? #=> false ShellResult.new('a', 'uh-oh').success? #=> false
# File lib/execute_shell/shell_result.rb, line 58 def success? @err.nil? || @err.empty? end