(self, args, bufsize=0, executable=None,
                 stdin=None, stdout=None, stderr=None,
                 preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,
                 shell=False, cwd=None, env=None, universal_newlines=False,
                 startupinfo=None, creationflags=0,
                 restore_signals=True, start_new_session=False,
                 pass_fds=())
Create new Popen instance.
Create new Popen instance.
Create new Popen instance .
def __init__(self, args, bufsize=0, executable=None,
                 stdin=None, stdout=None, stderr=None,
                 preexec_fn=None, close_fds=_PLATFORM_DEFAULT_CLOSE_FDS,
                 shell=False, cwd=None, env=None, universal_newlines=False,
                 startupinfo=None, creationflags=0,
                 restore_signals=True, start_new_session=False,
                 pass_fds=()):
        """Create new Popen instance."""
        _cleanup()

        self._child_created = False
        if bufsize is None:
            bufsize = 0  # Restore default
        if not isinstance(bufsize, int):
            raise TypeError("bufsize must be an integer")

        if mswindows:
            if preexec_fn is not None:
                raise ValueError("preexec_fn is not supported on Windows "
                                 "platforms")
            any_stdio_set = (stdin is not None or stdout is not None or
                             stderr is not None)
            if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
                if any_stdio_set:
                    close_fds = False
                else:
                    close_fds = True
            elif close_fds and any_stdio_set:
                raise ValueError(
                        "close_fds is not supported on Windows platforms"
                        " if you redirect stdin/stdout/stderr")
        else:
            # POSIX
            if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS:
                close_fds = True
            if pass_fds and not close_fds:
                warnings.warn("pass_fds overriding close_fds.", RuntimeWarning)
                close_fds = True
            if startupinfo is not None:
                raise ValueError("startupinfo is only supported on Windows "
                                 "platforms")
            if creationflags != 0:
                raise ValueError("creationflags is only supported on Windows "
                                 "platforms")

        self.stdin = None
        self.stdout = None
        self.stderr = None
        self.pid = None
        self.returncode = None
        self.universal_newlines = universal_newlines

        # Input and output objects. The general principle is like
        # this:
        #
        # Parent                   Child
        # ------                   -----
        # p2cwrite   ---stdin--->  p2cread
        # c2pread    <--stdout---  c2pwrite
        # errread    <--stderr---  errwrite
        #
        # On POSIX, the child objects are file descriptors.  On
        # Windows, these are Windows file handles.  The parent objects
        # are file descriptors on both platforms.  The parent objects
        # are -1 when not using PIPEs. The child objects are -1
        # when not redirecting.

        (p2cread, p2cwrite,
         c2pread, c2pwrite,
         errread, errwrite) = self._get_handles(stdin, stdout, stderr)

        # We wrap OS handles *before* launching the child, otherwise a
        # quickly terminating child could make our fds unwrappable
        # (see #8458).

        if mswindows:
            if p2cwrite != -1:
                p2cwrite = msvcrt.open_osfhandle(p2cwrite.Detach(), 0)
            if c2pread != -1:
                c2pread = msvcrt.open_osfhandle(c2pread.Detach(), 0)
            if errread != -1:
                errread = msvcrt.open_osfhandle(errread.Detach(), 0)

        if p2cwrite != -1:
            self.stdin = io.open(p2cwrite, 'wb', bufsize)
            if self.universal_newlines:
                self.stdin = io.TextIOWrapper(self.stdin, write_through=True)
        if c2pread != -1:
            self.stdout = io.open(c2pread, 'rb', bufsize)
            if universal_newlines:
                self.stdout = io.TextIOWrapper(self.stdout)
        if errread != -1:
            self.stderr = io.open(errread, 'rb', bufsize)
            if universal_newlines:
                self.stderr = io.TextIOWrapper(self.stderr)

        try:
            self._execute_child(args, executable, preexec_fn, close_fds,
                                pass_fds, cwd, env, universal_newlines,
                                startupinfo, creationflags, shell,
                                p2cread, p2cwrite,
                                c2pread, c2pwrite,
                                errread, errwrite,
                                restore_signals, start_new_session)
        except:
            # Cleanup if the child failed starting
            for f in filter(None, [self.stdin, self.stdout, self.stderr]):
                try:
                    f.close()
                except EnvironmentError:
                    # Ignore EBADF or other errors
                    pass
            raise
def __init__ ( self , args , bufsize = 0 , executable = None , stdin = None , stdout = None , stderr = None , preexec_fn = None , close_fds = _PLATFORM_DEFAULT_CLOSE_FDS , shell = False , cwd = None , env = None , universal_newlines = False , startupinfo = None , creationflags = 0 , restore_signals = True , start_new_session = False , pass_fds = ( ) ) : _cleanup ( ) self . _child_created = False if bufsize is None : bufsize = 0 # Restore default if not isinstance ( bufsize , int ) : raise TypeError ( "bufsize must be an integer" ) if mswindows : if preexec_fn is not None : raise ValueError ( "preexec_fn is not supported on Windows " "platforms" ) any_stdio_set = ( stdin is not None or stdout is not None or stderr is not None ) if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS : if any_stdio_set : close_fds = False else : close_fds = True elif close_fds and any_stdio_set : raise ValueError ( "close_fds is not supported on Windows platforms" " if you redirect stdin/stdout/stderr" ) else : # POSIX if close_fds is _PLATFORM_DEFAULT_CLOSE_FDS : close_fds = True if pass_fds and not close_fds : warnings . warn ( "pass_fds overriding close_fds." , RuntimeWarning ) close_fds = True if startupinfo is not None : raise ValueError ( "startupinfo is only supported on Windows " "platforms" ) if creationflags != 0 : raise ValueError ( "creationflags is only supported on Windows " "platforms" ) self . stdin = None self . stdout = None self . stderr = None self . pid = None self . returncode = None self . universal_newlines = universal_newlines # Input and output objects. The general principle is like # this: # # Parent                   Child # ------                   ----- # p2cwrite   ---stdin--->  p2cread # c2pread    <--stdout---  c2pwrite # errread    <--stderr---  errwrite # # On POSIX, the child objects are file descriptors.  On # Windows, these are Windows file handles.  The parent objects # are file descriptors on both platforms.  The parent objects # are -1 when not using PIPEs. The child objects are -1 # when not redirecting. ( p2cread , p2cwrite , c2pread , c2pwrite , errread , errwrite ) = self . _get_handles ( stdin , stdout , stderr ) # We wrap OS handles *before* launching the child, otherwise a # quickly terminating child could make our fds unwrappable # (see #8458). if mswindows : if p2cwrite != - 1 : p2cwrite = msvcrt . open_osfhandle ( p2cwrite . Detach ( ) , 0 ) if c2pread != - 1 : c2pread = msvcrt . open_osfhandle ( c2pread . Detach ( ) , 0 ) if errread != - 1 : errread = msvcrt . open_osfhandle ( errread . Detach ( ) , 0 ) if p2cwrite != - 1 : self . stdin = io . open ( p2cwrite , 'wb' , bufsize ) if self . universal_newlines : self . stdin = io . TextIOWrapper ( self . stdin , write_through = True ) if c2pread != - 1 : self . stdout = io . open ( c2pread , 'rb' , bufsize ) if universal_newlines : self . stdout = io . TextIOWrapper ( self . stdout ) if errread != - 1 : self . stderr = io . open ( errread , 'rb' , bufsize ) if universal_newlines : self . stderr = io . TextIOWrapper ( self . stderr ) try : self . _execute_child ( args , executable , preexec_fn , close_fds , pass_fds , cwd , env , universal_newlines , startupinfo , creationflags , shell , p2cread , p2cwrite , c2pread , c2pwrite , errread , errwrite , restore_signals , start_new_session ) except : # Cleanup if the child failed starting for f in filter ( None , [ self . stdin , self . stdout , self . stderr ] ) : try : f . close ( ) except EnvironmentError : # Ignore EBADF or other errors pass raise