Created: 2014-05-19 07:48
Updated: 2017-11-08 11:36



Using lua-filterpipe, this package provides convenience wrapper functions around the classic binutils and/or coreutils like cat, tac, head, tail etc so that they can be used with ease as filters from Lua programs.

In addition, this package provides a pipe object that makes using Unix pipelines in Lua programs extremely easy. It stores the pipeline's output and can be referred to or continued at any later point. Here's how it works:

local sh = require 'shellio'

-- let's get a list of a user's connection endpoints!

local P =
  ("lsof", "-i")
  ("grep", os.getenv("USER"))
  ("awk", "-F->", "{print $2}")
  ("cut", "-d:", "-f1")

print( -- the .data member contains the pipe's output

P("tac") -- continue processing the output

print( -- print the altered output

There's also a stack feature which keeps the results of every pipe component in memory. Just construct the pipe with a true argument:

local Q =

and after a pipe invocation,


will hold an array of all intermediate also the final result. You have to clear the stack memory manually. For this, just call the stack:


If you call the stack with a non-nil argument,


then this call is equivalent to


and may be used to construct an iterator over the stack elements.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more