Class: Pipe
- Inherits:
-
Object
- Object
- Pipe
- Defined in:
- lib/pipe-run.rb,
lib/em-pipe-run.rb
Overview
Pipe class of the pipe-run. Currently with one static method only.
Defined Under Namespace
Classes: Receiver
Class Method Summary collapse
-
.run(command, &block) ⇒ String
Runs the command and returns its standard output.
-
.run_nonblock(command, &block) ⇒ Object
Runs the command and returns its standard output.
Class Method Details
.run(command, &block) ⇒ String
Runs the command and returns its standard output.
If block is given, treat call as non-blocking. In that case, em-pipe-run file must be loaded.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pipe-run.rb', line 21 def self.run(command, &block) if not block.nil? return self.run_nonblock(command, &block) end ### pipe = File.popen(command, "r") result = pipe.read pipe.close() return result end |
.run_nonblock(command, &block) ⇒ Object
Runs the command and returns its standard output. Blocking.
72 73 74 75 |
# File 'lib/em-pipe-run.rb', line 72 def self.run_nonblock(command, &block) pipe = File.popen(command, "r") EM::attach(pipe, Receiver, block) end |