'The parameter \'cmd\' is the shell command to execute in a
sub-process.  On UNIX, \'cmd\' may be a sequence, in which case arguments
will be passed directly to the program without shell intervention (as
with os.spawnv()).  If \'cmd\' is a string it will be passed to the shell
(as with os.system()).   The \'capturestderr\' flag, if true, specifies
that the object should capture standard error output of the child
process.  The default is false.  If the \'bufsize\' parameter is
specified, it specifies the size of the I/O buffers to/from the child
process.'

def __init__(self, cmd, capturestderr=False, bufsize=(-1)):

    _cleanup()
    self.cmd = cmd
    (p2cread, p2cwrite) = os.pipe()
    (c2pread, c2pwrite) = os.pipe()
    if capturestderr:
        (errout, errin) = os.pipe()
    self.pid = os.fork()
    if (self.pid == 0):
        os.dup2(p2cread, 0)
        os.dup2(c2pwrite, 1)
        if capturestderr:
            os.dup2(errin, 2)
        self._run_child(cmd)
    os.close(p2cread)
    self.tochild = os.fdopen(p2cwrite, 'w', bufsize)
    os.close(c2pwrite)
    self.fromchild = os.fdopen(c2pread, 'r', bufsize)
    if capturestderr:
        os.close(errin)
        self.childerr = os.fdopen(errout, 'r', bufsize)
    else:
        self.childerr = None
    return
