Class: Pipe

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • command (String)

    command for run

  • block (Proc)

    block for giving back the results

Returns:

  • (String)

    command output



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.

Parameters:

  • command (String)

    command for run

  • block (Proc)

    callback for giving back the results

Since:

  • 0.2.0



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