lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I don't remember why, but I remember looking for a way to achieve this
with luaposix, not grasping how to do it (for now obvious reasons),
and looking elsewhere.

Pretty cool :-)

-- Pierre-Yves


On Sun, Mar 17, 2013 at 11:42 PM, Reuben Thomas <rrt@sc3d.org> wrote:
> The latest (5.1.27) of luaposix has a somewhat experimental addition,
> posix.pipeline, which allows process pipelines to be constructed in
> Lua, a mixture of shell commands and forked Lua functions run in
> subprocesses.
>
> For example, you can write something like:
>
> posix.pipeline({
>   "tail -3 COPYING",
>   "wc",
>   function () s = posix.read(posix.STDIN_FILENO, 1000) print (s) end
> })
>
> Even more experimentally, there's an iterator which adds an extra
> process and pipes the output of the end of the pipeline back into the
> calling process.
>
> Normally, posix.pipe is used to construct the pipe, but any function
> that returns paired file descriptors also works, e.g. posix.openpty.
>
> The reason for mentioning all this on the list is that I think it's
> pretty cool (being able to write process pipelines simply in Lua), but
> I have no idea if it's of interest to anyone else, and, if so, whether
> the API and, secondarily, code, seem sensible.
>
> I'm already using it in another project for coloring the output of
> command-line commands:
>
> https://github.com/rrthomas/cw
>
> Comments about the pipeline code and API are most welcome,
> particularly on the relevant github issue
>
> https://github.com/luaposix/luaposix/issues/74
>
> --
> http://rrt.sc3d.org
>