Class: Ladle::RubyProcess
- Inherits:
-
Object
- Object
- Ladle::RubyProcess
- Defined in:
- lib/ladle/ruby_process.rb
Overview
Implementations of platform-specific process handling behaviors for Ruby.
Instance Method Summary collapse
-
#initialize(*command_and_args) ⇒ RubyProcess
constructor
Create a new process for the given command and its args.
-
#pid ⇒ Fixnum
The PID for the process.
-
#popen ⇒ [IO, IO, IO]
Start the process and return pipes to its standard streams.
-
#stop_gracefully
Send signal 15 to the process.
-
#wait ⇒ Fixnum
Wait for the process to finish.
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
#pid ⇒ Fixnum
Returns 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.
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 |
#wait ⇒ Fixnum
Wait for the process to finish.
28 29 30 |
# File 'lib/ladle/ruby_process.rb', line 28 def wait Process.waitpid2(@pid)[1] end |