lua-users home
lua-l archive

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


Quoth Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>, on 2010-02-27 09:34:49 -0300:
> I get this in Linux:
> 
> > f = assert(io.popen("true", "w"))
> > =f:write "Hello, world."
> true
> > =f:close()
> Broken pipe
> (program exits)

I get the same result Rob Kendrick got on my Debian unstable system.
I believe the "Broken pipe" message is just not printed by default on
his and my system, which makes sense for processes in the middle of
pipelines.  E.g., on my machine, a C program that does raise(SIGPIPE)
also exits silently, but raise(SIGKILL) displays a message first.

> I don't think it can be improved at all if f:write returns true. Of course,
> f:write probably just buffers the output because if I replace f:close with
> f:flush I get the same error (Broken pipe).

More specifically, I imagine "improving" it in this case would
introduce a distinctly nonportable element for not very much gain.
The theoretically correct way to do it is presumably to add a SIGPIPE
handler to the application at the C level if it's a concern for that
program, and then the application can deal with avoiding doing this on
non-Unixy systems, again if it's a concern for that program.  (Whether
this is practical is another kettle of fish.)

   ---> Drake Wilson