How do you construct a read-write pipe with lua?

后端 未结 7 1138
甜味超标
甜味超标 2020-12-09 04:26

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

7条回答
  •  孤城傲影
    2020-12-09 05:06

    It's easy, no extensions necessary (tested with lua 5.3).

    #!/usr/bin/lua
    -- use always locals
    local stdin = io.stdin:lines()
    local stdout = io.write
    
    for line in stdin do
        stdout (line)
    end 
    

    save as inout.lua and do chmod +x /tmp/inout.lua

    20:30 $ foo=$(echo "bla"|  /tmp/inout.lua)
    20:30 $ echo $foo
    bla
    

提交回复
热议问题