Catching pipe errors when writing to standard input
A straightforward way to avoid this on Unix is to use a socketpair rather than a pipe for sending input to the subprocess. Still use pipes within a pipeline, of course - there, the SIGPIPE behavior is correct. But pipes are optimized for pipelines, and for other communication with a subprocess it's better to use a socketpair.
Catching pipe errors when writing to standard input
A straightforward way to avoid this on Unix is to use a socketpair rather than a pipe for sending input to the subprocess. Still use pipes within a pipeline, of course - there, the SIGPIPE behavior is correct. But pipes are optimized for pipelines, and for other communication with a subprocess it's better to use a socketpair.