Class: Flaky::Cmd

Inherits:
Object
  • Object
show all
Defined in:
lib/flaky/cmd.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd) ⇒ Cmd

Returns a new instance of Cmd.



5
6
7
8
9
# File 'lib/flaky/cmd.rb', line 5

def initialize cmd
  # redirect err to child's out
  @pid, @in, @out, @err = POSIX::Spawn::popen4 cmd, { :err => [:child, :out] }
  @in.close
end

Instance Attribute Details

#errObject (readonly)

Returns the value of attribute err.



3
4
5
# File 'lib/flaky/cmd.rb', line 3

def err
  @err
end

#inObject (readonly)

Returns the value of attribute in.



3
4
5
# File 'lib/flaky/cmd.rb', line 3

def in
  @in
end

#outObject (readonly)

Returns the value of attribute out.



3
4
5
# File 'lib/flaky/cmd.rb', line 3

def out
  @out
end

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/flaky/cmd.rb', line 3

def pid
  @pid
end

Instance Method Details

#stopObject



11
12
13
14
15
16
17
18
# File 'lib/flaky/cmd.rb', line 11

def stop
  [@in, @out, @err].each { |io| io.close unless io.nil? || io.closed? }
  begin
    Process.kill 'KILL', @pid
    Process.waitpid @pid
  rescue # no such process
  end
end