Module: XArgs

Defined in:
lib/xargs.rb

Overview

Skeleton module for the ‘xargs’ routine.

Ideally, one would do this in their code to import the “xargs” call directly into their current namespace:

require 'xargs'
include XArgs
# do something with xargs()

It is recommended that you look at the documentation for the xargs() call directly for specific usage.

The compilation of software known as xargs.rb is distributed under the following terms: Copyright © 2005-2006 Erik Hollensbe. All rights reserved.

Redistribution and use in source form, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright

notice, this list of conditions and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

++

Class Method Summary collapse

Class Method Details

.xargs(program, &block) ⇒ Object

Emulate the ‘xargs’ shell utility.

Takes a program to execute, and a block. The block is fed a line of input, which the code can do anything it wishes with.

Ex:

XArgs.xargs("find . -type f") { |line| puts line }


51
52
53
54
55
# File 'lib/xargs.rb', line 51

def xargs(program, &block)
  io = IO.popen("/usr/bin/env " + program)
  io.each_line { |line| yield line }
  io.close
end