def _popen( self, executable, argv, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=None, env=None, new_session=False, **kwargs ): if new_session: if has_new_subprocess: kwargs["start_new_session"] = True elif IS_WIN32: kwargs["creationflags"] = kwargs.get("creationflags", 0) | subprocess.CREATE_NEW_PROCESS_GROUP else: def preexec_fn(prev_fn=kwargs.get("preexec_fn", lambda: None)): os.setsid() prev_fn() kwargs["preexec_fn"] = preexec_fn if IS_WIN32 and "startupinfo" not in kwargs and stdin not in (sys.stdin, None): from plumbum.machines._windows import get_pe_subsystem, IMAGE_SUBSYSTEM_WINDOWS_CUI subsystem = get_pe_subsystem(str(executable)) if subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI: # don't open a new console sui = subprocess.STARTUPINFO() kwargs["startupinfo"] = sui if hasattr(subprocess, "_subprocess"): sui.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW # @UndefinedVariable sui.wShowWindow = subprocess._subprocess.SW_HIDE # @UndefinedVariable else: sui.dwFlags |= subprocess.STARTF_USESHOWWINDOW # @UndefinedVariable sui.wShowWindow = subprocess.SW_HIDE # @UndefinedVariable if not has_new_subprocess and "close_fds" not in kwargs: if IS_WIN32 and (stdin is not None or stdout is not None or stderr is not None): # we can't close fds if we're on windows and we want to redirect any std handle kwargs["close_fds"] = False else: kwargs["close_fds"] = True if cwd is None: cwd = self.cwd if env is None: env = self.env if isinstance(env, BaseEnv): env = env.getdict() if self._as_user_stack: argv, executable = self._as_user_stack[-1](argv) logger.debug("Running %r", argv) proc = IterablePopen( argv, executable=str(executable), stdin=stdin, stdout=stdout, stderr=stderr, cwd=str(cwd), env=env, **kwargs ) # bufsize = 4096 proc._start_time = time.time() proc.encoding = self.encoding proc.argv = argv return proc
def _popen(self, executable, argv, stdin = PIPE, stdout = PIPE, stderr = PIPE, cwd = None, env = None, new_session = False, **kwargs): if new_session: if has_new_subprocess: kwargs["start_new_session"] = True elif IS_WIN32: kwargs["creationflags"] = kwargs.get("creationflags", 0) | subprocess.CREATE_NEW_PROCESS_GROUP else: def preexec_fn(prev_fn = kwargs.get("preexec_fn", lambda: None)): os.setsid() prev_fn() kwargs["preexec_fn"] = preexec_fn if IS_WIN32 and "startupinfo" not in kwargs and stdin not in (sys.stdin, None): from plumbum.machines._windows import get_pe_subsystem, IMAGE_SUBSYSTEM_WINDOWS_CUI subsystem = get_pe_subsystem(str(executable)) if subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI: # don't open a new console sui = subprocess.STARTUPINFO() kwargs["startupinfo"] = sui if hasattr(subprocess, "_subprocess"): sui.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW # @UndefinedVariable sui.wShowWindow = subprocess._subprocess.SW_HIDE # @UndefinedVariable else: sui.dwFlags |= subprocess.STARTF_USESHOWWINDOW # @UndefinedVariable sui.wShowWindow = subprocess.SW_HIDE # @UndefinedVariable if not has_new_subprocess and "close_fds" not in kwargs: if IS_WIN32 and (stdin is not None or stdout is not None or stderr is not None): # we can't close fds if we're on windows and we want to redirect any std handle kwargs["close_fds"] = False else: kwargs["close_fds"] = True if cwd is None: cwd = self.cwd if env is None: env = self.env if isinstance(env, BaseEnv): env = env.getdict() if self._as_user_stack: argv, executable = self._as_user_stack[-1](argv) logger.debug("Running %r", argv) proc = IterablePopen(argv, executable = str(executable), stdin = stdin, stdout = stdout, stderr = stderr, cwd = str(cwd), env = env, **kwargs) # bufsize = 4096 proc._start_time = time.time() proc.custom_encoding = self.custom_encoding proc.argv = argv return proc
def _popen( self, executable, argv, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=None, env=None, new_session=False, **kwargs, ): if new_session: kwargs["start_new_session"] = True if IS_WIN32 and "startupinfo" not in kwargs and stdin not in ( sys.stdin, None): subsystem = get_pe_subsystem(str(executable)) if subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI: # don't open a new console sui = subprocess.STARTUPINFO() kwargs["startupinfo"] = sui if hasattr(subprocess, "_subprocess"): sui.dwFlags |= (subprocess._subprocess.STARTF_USESHOWWINDOW ) # @UndefinedVariable sui.wShowWindow = (subprocess._subprocess.SW_HIDE ) # @UndefinedVariable else: sui.dwFlags |= subprocess.STARTF_USESHOWWINDOW # @UndefinedVariable sui.wShowWindow = subprocess.SW_HIDE # @UndefinedVariable if cwd is None: cwd = self.cwd envs = [self.env, env] env = {} for _env in envs: if not _env: continue if isinstance(_env, BaseEnv): _env = _env.getdict() env.update(_env) if self._as_user_stack: argv, executable = self._as_user_stack[-1](argv) logger.debug("Running %r", argv) proc = PlumbumLocalPopen( argv, executable=str(executable), stdin=stdin, stdout=stdout, stderr=stderr, cwd=str(cwd), env=env, **kwargs, ) # bufsize = 4096 proc._start_time = time.time() proc.custom_encoding = self.custom_encoding proc.argv = argv return proc