Sha256: 8eb8248a5afd284f71d61de16541ab859c63121093de0a6c64844ddb15f60660

Contents?: true

Size: 584 Bytes

Versions: 8

Compression:

Stored size: 584 Bytes

Contents

require "tempfile"

# Allows one to get stdout and stderr from an executed command. Original version
# by Karl von Laudermann in ruby-talk #113035
class ExtendedCommand

  attr_reader :ret_code, :out_text, :err_text

  def initialize( command )
    tempfile = Tempfile.new( 'webgen' )
    tempfile.close  # So that child process can write to it

    # Execute command, redirecting stderr to temp file
    @out_text = `#{command} 2> #{tempfile.path}`
    @ret_code = $? >> 8

    # Read temp file
    tempfile.open
    @err_text = tempfile.readlines.join
    tempfile.close
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
webgen-0.4.1 lib/webgen/extcommand.rb
webgen-0.4.2 lib/webgen/extcommand.rb
webgen-0.4.0 lib/webgen/extcommand.rb
webgen-0.4.5 lib/webgen/extcommand.rb
webgen-0.4.3 lib/webgen/extcommand.rb
webgen-0.4.4 lib/webgen/extcommand.rb
webgen-0.4.6 lib/webgen/extcommand.rb
webgen-0.4.7 lib/webgen/extcommand.rb