How do I use file descriptors other than std[in/out/err] in python?
Question: I need to pipe two streams of data to an external program from a Python (3.4)
script. One can go to STDIN, and I'm ok on that:

    
    
    from subprocess import check_output
    
    data1 = b'This is the data to pass on stdin'
    check_output(['externalprogram'], input=data1)
    

The program can accept the other piece on a file descriptor given on the
command line, but how do I tell python to send data on another fd?

    
    
    data2 = b'This is the data to pass on fd 3'
    check_output(['externalprogram', '-data2fd', '3'], input=data1, ???)
    

I imagine I may need to go a layer deeper and use `Popen`, but I still don't
see how to do it.


Answer: On linux at least, you can use `os.pipe` to create a pipe. When the child is
called, it inherits the parent pipe. The parent should close the read end to
avoid spurious signals, then write to the write side of the pipe. The child
can then read from the read end of the pipe.

