lua-users home
lua-l archive

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


On 10/9/07, Edgar Toernig <froese@gmx.de> wrote:
> To see what's wrong let's shove bigger chunks of data into
> the filter:
>
>         fp:write(about_64k_of_data)
>         fp:flush_output()
>         fp:close_output()
>         x = fp:read("*a")
>
> 64k should be big enough to fill all buffers between
> the parent and the filter process (the actual value
> differs greatly between systems).  What happens?  The
> program hangs again!  Why?  Because the parent is still
> trying to write data to the filter but the filter is no
> longer reading the data.  It is trying to pass already
> processes data back to the parent.  Deadlock!

popen2 traditionally returns _two_ file objects, one for writing and
one for reading.
How about this implementation?

http://mysite.mweb.co.za/residents/sdonovan/popen.zip

(on Fedora Core 5)
> require 'popen'
> w,r = popen.popen2('cat')
> w:write(string.rep('*',64*1024))
> w:close()
> res = r:read('*a')
> = #res
65536

Have I missed something here?

steve d.