def popen(patch, cmd, mode="r", bufsize=0):
    """Open a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. The bufsize argument has the same meaning as the corresponding argument to the built-in open() function. The exit status of the command (encoded in the format specified for wait()) is available as the return value of the close() method of the file object, except that when the exit status is zero (termination without errors), None is returned."""
    cmd = _PopenCmd(cmd, mode, bufsize, shared_eo=False)
    pipes = cmd.get_pipes()
    cmd.run()
    if mode == "r":
        return pipes[1]
    elif mode == "w":
        return pipes[0]
Open a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. The bufsize argument has the same meaning as the corresponding argument to the built-in open() function. The exit status of the command (encoded in the format specified for wait()) is available as the return value of the close() method of the file object, except that when the exit status is zero (termination without errors), None is returned.
lib/mlpatches/os_popen.py