How to get output of piped process?

Steven Schveighoffer schveiguy at gmail.com
Fri Feb 19 13:42:46 UTC 2021


On 2/19/21 5:41 AM, kdevel wrote:
> On Friday, 19 February 2021 at 08:37:50 UTC, Imperatorn wrote:
>> Does your iopipe handle... Pipes? 😀
> 
> BTW: What about SIGPIPE?
> 
> In an experimental code I have this
> 
>     :
>     fout.rawWrite (buf);
>     fout.rawWrite ("\n");
>     writeln ("flushing");
>     fout.flush ();                                    // (a)
>     enforce (! fout.eof, "eof on write to child");    // (b)
>     writeln ("reading from pipe");
>     :
> 
> fout actually is the child's stdin. Sometimes between (a) and (b)
> a SIGPIPE occurs and terminates the process (exit code 141). That
> prevents the proper handling of eof.
> 
> Why isn't SIGPIPE blocked or handled by default?

ignoring SIGPIPE is a process-wide thing, and so it's not appropriate 
for Phobos to make that decision for you. But it's trivial to ignore it.

I've never been a fan of SIGPIPE. If you look around on the Internet, 
you'll find that most people agree that the reasoning for SIGPIPE is to 
fix poor programming (i.e. ignoring of error codes). But it doesn't give 
you any good way to handle it. A SIGPIPE can be due to any pipe being 
written, it doesn't tell you which one. In order to know which one 
caused it, well, you have to look at the error code of the call!

The end result is -- it makes poor programming the standard. If you 
ignore SIGPIPE for a child process, then if that process' operation 
depends on SIGPIPE killing it, then you have screwed over that child 
process, or rather, exposed the lack of error checking in the child process.

-Steve


More information about the Digitalmars-d-learn mailing list