Class: Ladle::RubyProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/ladle/ruby_process.rb

Overview

Implementations of platform-specific process handling behaviors for Ruby.

Instance Method Summary collapse

Constructor Details

#initialize(*command_and_args) ⇒ RubyProcess

Create a new process for the given command and its args.



11
12
13
# File 'lib/ladle/ruby_process.rb', line 11

def initialize(*command_and_args)
  @command_and_args = command_and_args
end

Instance Method Details

#pidFixnum

Returns the PID for the process.

Returns:

  • (Fixnum)

    the PID for the process



42
43
44
# File 'lib/ladle/ruby_process.rb', line 42

def pid
  @pid
end

#popen[IO, IO, IO]

Start the process and return pipes to its standard streams.

Returns:

  • ([IO, IO, IO])

    stdin, stdout, and stderr for the running process.



19
20
21
22
# File 'lib/ladle/ruby_process.rb', line 19

def popen
  @pid, i, o, e = Open4.open4(@command_and_args.join(' '))
  [i, o, e]
end

#stop_gracefully

This method returns an undefined value.

Send signal 15 to the process.



36
37
38
# File 'lib/ladle/ruby_process.rb', line 36

def stop_gracefully
  Process.kill 15, pid
end

#waitFixnum

Wait for the process to finish.

Returns:

  • (Fixnum)

    the return status of the process.



28
29
30
# File 'lib/ladle/ruby_process.rb', line 28

def wait
  Process.waitpid2(@pid)[1]
end