Open
Description
$ cat foo.rb
puts "These are the args: #{ARGV.inspect}"
puts "This is STDIN: #{STDIN.read}"
$
$ cat bar.lua
print("hi")
local named_pipe = '/tmp/pun-boot-pipe-' .. math.random(0,10000000)
print("named pipe created: " .. named_pipe)
os.execute('mkfifo ' .. named_pipe)
local handle = io.popen("cat " .. named_pipe .. " | ruby foo.rb a b c", "r")
local stdin_handle = io.open(named_pipe, "w")
stdin_handle:write("1 2 3 4 5 6")
stdin_handle:close()
local output = handle:read("*a")
handle:close()
os.execute('rm ' .. named_pipe)
print("printing captured output")
print(output)
$
$ lua bar.lua
hi
named pipe created: /tmp/pun-boot-pipe-8401878
printing captured output
These are the args: ["a", "b", "c"]
This is STDIN: 1 2 3 4 5 6
First use os.tmpname()
. Second, be able to explain this:
local output = handle:read("*a")
does not execute tillstdin_handle:write("1 2 3 4 5 6")
and thenstdin_handle:close()
are complete and thenlocal output = handle:read("*a")
would not complete untillocal handle = io.popen("cat " .. named_pipe .. " | ruby foo.rb a b c", "r")
completed- why placing
local stdin_handle = io.open(named_pipe, "w")
beforelocal handle = io.popen("cat " .. named_pipe .. " | ruby foo.rb a b c", "r")
causes the application to hang
Metadata
Metadata
Assignees
Labels
No labels