You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ 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 till stdin_handle:write("1 2 3 4 5 6") and then stdin_handle:close() are complete and then local output = handle:read("*a") would not complete until local handle = io.popen("cat " .. named_pipe .. " | ruby foo.rb a b c", "r") completed
why placing local stdin_handle = io.open(named_pipe, "w") before local handle = io.popen("cat " .. named_pipe .. " | ruby foo.rb a b c", "r") causes the application to hang
The text was updated successfully, but these errors were encountered:
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")
completedlocal 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 hangThe text was updated successfully, but these errors were encountered: