Module: EventMachine
- Defined in:
- lib/em-popen3/popen3.rb,
lib/em-popen3/version.rb
Defined Under Namespace
Modules: POpen3
Class Method Summary collapse
-
.popen3(cmd, stream_callbacks) ⇒ Object
EM::popen3 is used to launch given command and capture the stdin, stdout and stderr streams.
Class Method Details
.popen3(cmd, stream_callbacks) ⇒ Object
EM::popen3 is used to launch given command and capture the stdin, stdout and stderr streams.
Example: EM.run do
p = EM.popen3('ls', {
:stdout => Proc.new { |data| puts "stdout: #{data}" },
:stderr => Proc.new { |data| puts "stderr: #{data}" }
})
p.callback do
puts "All good"
end
p.errback do |err_code|
puts "Error: #{err_code}"
end
end
It returns a deferrable object
26 27 28 29 30 31 32 |
# File 'lib/em-popen3/popen3.rb', line 26 def self.popen3(cmd, stream_callbacks) raise ArgumentError, "stream_callbacks must be specified" unless stream_callbacks raise ArgumentError, ":stdout callback must be specified" unless stream_callbacks[:stdout].is_a?(Proc) raise ArgumentError, ":stderr callback must be specified" unless stream_callbacks[:stderr].is_a?(Proc) POpen3::Wrapper.new(cmd, stream_callbacks) end |