Sha256: 5f6c831e32996ce0eba7f675ecd65f53ac791575c0296a2698b8504b2316977d

Contents?: true

Size: 593 Bytes

Versions: 16

Compression:

Stored size: 593 Bytes

Contents

require 'pty'
require 'mkit/exceptions'

module MKIt
  class CmdRunner
    def self.run(cmd)
      result=''
      begin
        shell = PTY.spawn( cmd )
        begin
          shell[0].each { |line| result << line.strip! }
        rescue Errno::EIO
          # nothing
        ensure
          shell[0].close
        end
        shell[1].close
        Process.wait(shell[2])
      rescue PTY::ChildExited
        # nothing
      end
      raise CmdRunnerException.new("command '#{cmd[0..30]}...' returned an error response") if !$?.nil? && $?.exitstatus != 0
      result
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mkit-0.9.0 lib/mkit/cmd_runner.rb
mkit-0.8.0 lib/mkit/cmd_runner.rb
mkit-0.7.2 lib/mkit/cmd_runner.rb
mkit-0.7.1 lib/mkit/cmd_runner.rb
mkit-0.7.0 lib/mkit/cmd_runner.rb
mkit-0.6.3 lib/mkit/cmd_runner.rb
mkit-0.6.2 lib/mkit/cmd_runner.rb
mkit-0.6.1 lib/mkit/cmd_runner.rb
mkit-0.6.0 lib/mkit/cmd_runner.rb
mkit-0.5.0 lib/mkit/cmd_runner.rb
mkit-0.4.3 lib/mkit/cmd_runner.rb
mkit-0.4.2 lib/mkit/cmd_runner.rb
mkit-0.4.1 lib/mkit/cmd_runner.rb
mkit-0.4.0 lib/mkit/cmd_runner.rb
mkit-0.3.0 lib/mkit/cmd_runner.rb
mkit-0.2.0 lib/mkit/cmd_runner.rb