I\'d like to do the equivalent of:
foo=$(echo \"$foo\"|someprogram)
within lua -- ie, I\'ve got a variable containing a bunch of text, and
Here is how I solved the problem, it require lua posix
.
p = require 'posix'
local r,w = p.pipe()
local r1,w1 = p.pipe()
local cpid = p.fork()
if cpid == 0 then -- child reads from pipe
w:close()
r1:close()
p.dup(r, io.stdin)
p.dup(w1 ,io.stdout)
p.exec('./myProgram')
r:close()
w1:close()
p._exit(0)
else -- parent writes to pipe
IN = r1
OUT = w
end
During myProgram
execution, you'l read and write from normal io and after this part of code you just have to write/read on IN
and OUT
to comunicate with child program.