So... I start another process that accepts some input from my program (it could go the other way around too). Something of the sort:
FILE *f(popen("sendmail", "w"));
Now, I can put f in an fstream so that way I can just use the stream (since my program is in C++, it seems to be a sensible thing to do.)
std::ofstream output(fileno(f));
...
output << "To: santa.claus@example.com" << std::endl;
...
Up to here, I'm good. Now comes the point where I'm done sending data to the child process. All I want is to close the pipe. From what I know, we are expected to use pclose() because that function ensures that the other process receives all the data. In otherwise words, the pclose() function knows how to cleanly severe a pipe.
Unfortunately, since I put f in an ofstream, I cannot just close it, can I?
pclose(f); // proper way to close a pipe
...
ofstream::~ofstream() { ... close(fd); ... } // not the right way to close a pipe
Is there a way to capture the close from the ofstream and ensure it closes the way I want it to eb closed.