Pipes between Python and C++ don't get closed
I am spawning a process in python using subprocess and want to read output from the program using pipes. The C++ program does not seem to close the pipe though, even when explicitly telling it to close.

    #include <cstdlib>
    #include <ext/stdio_filebuf.h>
    #include <iostream>

    int main(int argc, char **argv) {
      int fd = atoi(argv[1]);
      __gnu_cxx::stdio_filebuf<char> buffer(fd, std::ios::out);
      std::ostream stream(&buffer);
      stream << "Hello World" << std::endl;
      buffer.close();
      return 0;
    }

I invoke this small program with this python snippet:

    import os                                                                                         
    import subprocess                                                                                 
                                                                                                      
    read, write = os.pipe()                                                                           
    proc = subprocess.Popen(["./dummy", str(write)])                                                  
    data = os.fdopen(read, "r").read()                                                                
    print data                                                                                        

The read() method does not return, as the fd is not closed. Opening and closing the write fd in python solves the problem. But it seems like a hack to me. Is there a way to close the fd in my C++ process?

Thanks a lot!
Pipes between Python and C++ don't get closed
===

I am spawning a process in python using subprocess and want to read output from the program using pipes. The C++ program does not seem to close the pipe though, even when explicitly telling it to close.

    #include <cstdlib>
    #include <ext/stdio_filebuf.h>
    #include <iostream>

    int main(int argc, char **argv) {
      int fd = atoi(argv[1]);
      __gnu_cxx::stdio_filebuf<char> buffer(fd, std::ios::out);
      std::ostream stream(&buffer);
      stream << "Hello World" << std::endl;
      buffer.close();
      return 0;
    }

I invoke this small program with this python snippet:

    import os                                                                                         
    import subprocess                                                                                 
                                                                                                      
    read, write = os.pipe()                                                                           
    proc = subprocess.Popen(["./dummy", str(write)])                                                  
    data = os.fdopen(read, "r").read()                                                                
    print data                                                                                        

The read() method does not return, as the fd is not closed. Opening and closing the write fd in python solves the problem. But it seems like a hack to me. Is there a way to close the fd in my C++ process?

Thanks a lot!