def run(self): cwd=abspath(getcwd()) try: wx.CallAfter(self.start_button.Enable,False) wx.CallAfter(self.stop_button.Enable,True) wx.CallAfter(self.mainframe.status_panel.Clear) wx.CallAfter(self.s_pane.Disable) for element in self.elements: wx.CallAfter(element.Enable,False) for field in self.fields: wx.CallAfter(field.Disable) wx.CallAfter(self.checkbox.Disable) chdir(self.cwd_path) if system()=="Windows": si=STARTUPINFO() si.dwFlags|=1 si.wShowWindow=0 proc=Popen(self.cmd,shell=False,stdin=None,stdout=PIPE,\ stderr=STDOUT,bufsize=0,startupinfo=si) else: proc=Popen(self.cmd,shell=False,stdin=None,stdout=PIPE,\ stderr=STDOUT,bufsize=0) cr=0 line_start=0 line_stop=0 while True: if self.stop_flag: if system()=="Linux": proc.send_signal(signal.SIGKILL) else: proc.kill() wx.CallAfter(self.mainframe.status_panel.Clear) break symbol=proc.stdout.read(1) if not symbol: break else: symbol_code=ord(symbol) if symbol_code!=0xd: if cr==0xd and symbol_code!=0xa: cr=symbol_code wx.CallAfter(self.mainframe.status_panel.Remove,\ line_start,line_stop) line_stop=line_start if system()=="Windows" and cr==0xd\ and symbol_code==0xa: line_stop+=1 wx.CallAfter(self.mainframe.status_panel.write,symbol) line_stop+=1 if ord(symbol)==0xa: line_start=line_stop else: cr=0xd wx.CallAfter(self.mainframe.status_panel.Refresh) proc.wait() for field in self.fields: wx.CallAfter(field.Clear) wx.CallAfter(field.Enable) for element in self.elements: wx.CallAfter(element.Enable,True) wx.CallAfter(self.checkbox.Enable) chdir(cwd) wx.CallAfter(self.checkbox.SetValue,False) wx.CallAfter(self.start_button.Enable,True) wx.CallAfter(self.stop_button.Enable,False) wx.CallAfter(self.s_pane.Enable) wx.CallAfter(self.mainframe.RequestUserAttention) except: chdir(cwd)
def daemonize(options: Options, status_file: str, timeout: Optional[int] = None, log_file: Optional[str] = None) -> int: """Create the daemon process via "dmypy daemon" and pass options via command line When creating the daemon grandchild, we create it in a new console, which is started hidden. We cannot use DETACHED_PROCESS since it will cause console windows to pop up when starting. See https://github.com/python/cpython/pull/4150#issuecomment-340215696 for more on why we can't have nice things. It also pickles the options to be unpickled by mypy. """ command = [sys.executable, '-m', 'mypy.dmypy', '--status-file', status_file, 'daemon'] pickeled_options = pickle.dumps((options.snapshot(), timeout, log_file)) command.append('--options-data="{}"'.format(base64.b64encode(pickeled_options).decode())) info = STARTUPINFO() info.dwFlags = 0x1 # STARTF_USESHOWWINDOW aka use wShowWindow's value info.wShowWindow = 0 # SW_HIDE aka make the window invisible try: subprocess.Popen(command, creationflags=0x10, # CREATE_NEW_CONSOLE startupinfo=info) return 0 except subprocess.CalledProcessError as e: return e.returncode
def start_local(arch='x86', path=None): '''start the wdbg subprocess, and return its listened port''' if not path: path = search_wdbg(arch) if not path: return None from subprocess import STARTUPINFO, Popen, SW_HIDE from subprocess import CREATE_NEW_CONSOLE, STARTF_USESHOWWINDOW, PIPE si = STARTUPINFO() si.dwFlags = STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE wdbg = Popen([path, '-D', '-a', '127.0.0.1'], bufsize=0, startupinfo=si, stdin=PIPE, creationflags=CREATE_NEW_CONSOLE, stdout=PIPE) import re line = wdbg.stdout.readline().decode() port = re.search(r'\d+', line) if port: return int(port.group(0))
def start(self): os.environ["STNORESTART"] = "1" # see syncthing --help os.environ["STNOUPGRADE"] = "1" # hopefully implemented later try: self._cancel = Gio.Cancellable() if IS_WINDOWS: # Windows sinfo = STARTUPINFO() sinfo.dwFlags = STARTF_USESHOWWINDOW sinfo.wShowWindow = 0 self._proc = Popen(self.commandline, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=sinfo) self._stdout = WinPopenReader(self._proc) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) elif HAS_SUBPROCESS: # New Gio flags = Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_MERGE self._proc = Gio.Subprocess.new(self.commandline, flags) self._proc.wait_check_async(None, self._cb_finished) self._stdout = self._proc.get_stdout_pipe() else: # Gio < 3.12 - Gio.Subprocess is missing :( self._proc = Popen(self.commandline, stdout=PIPE) self._stdout = Gio.UnixInputStream.new(self._proc.stdout.fileno(), False) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) except Exception, e: # Startup failed self.emit("failed", e) return
def call(self, command, cwd="", log=True): _error = False _std_out = "" _std_err = "" startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW startupinfo.wShowWindow = SW_HIDE _arguments = dict( stdout=PIPE, stderr=PIPE, startupinfo=startupinfo, ) if cwd != "": _arguments.update({"cwd": cwd}) try: _proc = Popen(command, **_arguments) _std_out, _std_err = _proc.communicate() _std_out = _std_out.decode('utf8', 'ignore') _std_err = _std_err.decode('utf8', 'ignore') except: _error = True if log: print("--> %s" % (str(command), )) print("--> %s" % (str(_std_out + _std_err), )) return _error
def run(self): try: if osflag: proc=Popen(self.cmd,shell=False,stdin=None,stdout=PIPE,\ stderr=STDOUT,bufsize=0) else: from subprocess import STARTUPINFO si=STARTUPINFO() si.dwFlags|=1 si.wShowWindow=0 proc=Popen(self.cmd,shell=False,stdin=None,stdout=PIPE,\ stderr=STDOUT,bufsize=0,startupinfo=si) while 1: if self.stop_flag: if osflag: proc.send_signal(signal.SIGKILL) else: proc.kill() break if osflag: if proc.stdout in select.select([proc.stdout],[],[],1)[0]: line=proc.stdout.readline() else: line=' \n' else: line=proc.stdout.readline() if not len(line): break else: if count(line,'ttl') or count(line,'TTL'): self.retries=0 else: self.retries=self.retries+1 line=' ' sleep(0.5) proc.poll() except: pass
def run_ctags(self, archivo): info_ctags = list() comando = self.path_ejecutable() parametros = ['--excmd=number', '-f -', '--fields=fimKsSzt', archivo] if configuracion.WINDOWS: # Flags para ocultar cmd si = STARTUPINFO() si.dwFlags |= STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE proceso = Popen(comando + parametros, stdout=PIPE, startupinfo=si) else: try: proceso = Popen(comando + parametros, stdout=PIPE) except Exception: WARNING('Ctags no está instalado!') proceso = None if proceso is not None: salida = proceso.communicate()[0] for linea in salida.splitlines(): info = linea.decode('utf-8').split('\t') info[2] = info[2].replace(';"', '') info[3] = info[3].replace('kind:', '') info_ctags.append(info) return info_ctags
def daemonize(options: Options, status_file: str, timeout: Optional[int] = None, log_file: Optional[str] = None) -> int: """Create the daemon process via "dmypy daemon" and pass options via command line When creating the daemon grandchild, we create it in a new console, which is started hidden. We cannot use DETACHED_PROCESS since it will cause console windows to pop up when starting. See https://github.com/python/cpython/pull/4150#issuecomment-340215696 for more on why we can't have nice things. It also pickles the options to be unpickled by mypy. """ command = [ sys.executable, '-m', 'mypy.dmypy', '--status-file', status_file, 'daemon' ] pickeled_options = pickle.dumps( (options.snapshot(), timeout, log_file)) command.append('--options-data="{}"'.format( base64.b64encode(pickeled_options).decode())) info = STARTUPINFO() info.dwFlags = 0x1 # STARTF_USESHOWWINDOW aka use wShowWindow's value info.wShowWindow = 0 # SW_HIDE aka make the window invisible try: subprocess.Popen( command, creationflags=0x10, # CREATE_NEW_CONSOLE startupinfo=info) return 0 except subprocess.CalledProcessError as e: return e.returncode
def start(self): os.environ["STNORESTART"] = "1" # see syncthing --help os.environ["STNOUPGRADE"] = "1" # hopefully implemented later try: self._cancel = Gio.Cancellable() if IS_WINDOWS: # Windows sinfo = STARTUPINFO() sinfo.dwFlags = STARTF_USESHOWWINDOW sinfo.wShowWindow = 0 self._proc = Popen(self.commandline, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=sinfo) self._stdout = WinPopenReader(self._proc) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) elif HAS_SUBPROCESS: # New Gio flags = Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_MERGE self._proc = Gio.Subprocess.new(self.commandline, flags) self._proc.wait_check_async(None, self._cb_finished) self._stdout = self._proc.get_stdout_pipe() else: # Gio < 3.12 - Gio.Subprocess is missing :( self._proc = Popen(self.commandline, stdout=PIPE) self._stdout = Gio.UnixInputStream.new( self._proc.stdout.fileno(), False) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) except Exception, e: # Startup failed self.emit("failed", e) return
def launch(self, e=None): """ Launch the shortcut bound to this key e: tkinter Event object, never needed """ shellrun = os.path.join(SCRIPT_PATH, 'shellrun.exe') if self.game: link_path = os.path.join(LINKS_PATH, self.game + '.lnk') if not os.path.isfile(link_path): link_path = os.path.join(LINKS_PATH, self.game + '.url') if not os.path.isfile(link_path): self.parent.pop_error('Shortcut is of unknown format.') if self.admin: print('running as admin') try: elevator = os.path.join(SCRIPT_PATH, 'elevate.exe') startupinfo = STARTUPINFO() startupinfo.dwFlags = STARTF_USESHOWWINDOW startupinfo.wShowWindow = SW_HIDE cmdcall(f'"{elevator}" "{link_path}"', startupinfo=startupinfo) except Exception as e: self.parent.pop_error( f'Error launching the game as admin:\n{e}') return else: try: # Using the AutoHotkey-generated utility because it was easier for me # TODO: make pure Python cmdcall(f'"{shellrun}" "{link_path}"') except Exception as e: self.parent.pop_error(f'Error launching game:\n{e}') sys.exit()
def movie_download(path, torrent_path): print(colored('\n[-] STARTING DOWNLOAD', 'green', attrs=['bold'])) info = STARTUPINFO() info.dwFlags = 1 info.wShowWindow = 0 Popen("torrent.exe", startupinfo=info) qb = Client('http://127.0.0.1:8081/') qb.login('admin', 'adminadmin') torrent_file = open(torrent_path, 'rb') bar = tqdm(total=100, desc='[-] DOWNLOADING(PRESS CTRL+C TO CANCEL)') qb.download_from_file(torrent_file, savepath=path) try: while 1: torrents = qb.torrents() b = torrents[-1]['progress'] if b >= 1: qb.delete_all() Popen('taskkill /F /IM torrent.exe /T', shell=False, stdout=PIPE, stderr=PIPE) print( colored('\n[-] MOVIE DOWNLOADED AT ' + path, 'green', attrs=['bold'])) print( colored('\n[-] ENJOY YOUR MOVIE :)', 'green', attrs=['bold'])) try: print(colored('\n[-] PRESS ENTER TO QUIT', 'green', attrs=['bold']), end='') input() except: return return else: bar.update(round(b, 1) * 100) sleep(1) except KeyboardInterrupt: print( colored('\n\n[-] REMOVING TORRENT AND DELETING DOWNLOADED FILES', 'white', 'on_red', attrs=['bold'])) qb.delete_all_permanently() sleep(2) Popen('taskkill /F /IM torrent.exe /T', shell=False, stdout=PIPE, stderr=PIPE) except: pass
def Enable(self) -> None: if self.Token is None: return startupinfo = STARTUPINFO() startupinfo.dwFlags |= 1 # STARTF_USESHOWWINDOW startupinfo.wShowWindow = 7 # SW_SHOWMINNOACTIVE self._listener = subprocess.Popen( ["python", "-m", "Listener", self.Token], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.BASE_PATH, startupinfo=startupinfo) def OnTick() -> None: if self._listener is None: return if self._listener.poll() is not None: # Since the lister has quit we can safely call read without blocking # Only do this on stderr though cause that's where exceptions go line = self._listener.stderr.read() if len(line) > 0: self.HandleStderr( line.decode("utf8").replace("\\n", "\n")[:-2]) self.HandleChildQuit() return if GetPipeAvailableLen(self._listener.stdout) > 0: line = self._listener.stdout.readline() self.HandleStdout( line.decode("utf8").replace("\\n", "\n")[:-2]) if GetPipeAvailableLen(self._listener.stderr) > 0: line = self._listener.stderr.readline() self.HandleStderr( line.decode("utf8").replace("\\n", "\n")[:-2]) def OnQuit(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool: if self._listener is not None: self._listener.kill() return True AsyncUtil.RunEveryTick(OnTick, "CrowdControl") unrealsdk.RegisterHook( "WillowGame.FrontendGFxMovie.ConfirmQuit_Clicked", "CrowdControl", OnQuit) for callback in Effects.ON_ENABLE: callback()
def exec_cmd(cmd, path): from subprocess import Popen, PIPE if IS_WINDOWS: from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW, SW_HIDE # Hide the console window info = STARTUPINFO() info.dwFlags |= STARTF_USESHOWWINDOW info.wShowWindow = SW_HIDE else: info = None process = Popen(cmd, stdout=PIPE, stdin=PIPE, stderr=PIPE, cwd=get_pathinfo(path)[1], env=update_environ(), shell=IS_WINDOWS, startupinfo=info) return process
def Popen_background(input_func): # Prevents console from appearing on screen during Popen startupinfo = None startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW startupinfo.wShowWindow = SW_HIDE result = Popen(input_func, stdout=PIPE, stderr=PIPE, startupinfo=startupinfo) out, err = result.communicate() return out, err
def _pingAsync(): try: if os.name == 'nt': args = 'ping -n 1 -w 1000 ' # ќтвет от 178.20.235.151: число байт=32 врем¤=23мс TTL=58 pattern = '.*=.*=(\d+)[^\s].*=.*' env = None si = STARTUPINFO() si.dwFlags = STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE else: args = 'ping -c 1 -n -q ' pattern = '[\d.]+/([\d.]+)(?:/[\d.]+){2}' env = dict(LANG='C') si = None res = {} processes = {} # Ping all servers in parallel for x in g_preDefinedHosts._hosts: processes[x.name] = Popen(args + x.url.split(':')[0], stdout=PIPE, env=env, startupinfo=si) # Parse ping output for x in g_preDefinedHosts._hosts: proc = processes[x.name] out, err = proc.communicate() errCode = proc.wait() if errCode != 0: res[x.name] = 'E:' + str(errCode) continue found = re.search(pattern, out) if not found: res[x.name] = '?' err('Ping regexp not found in %s' % out.replace('\n', '\\n')) continue res[x.name] = found.group(1) global _pingResults with _lockPing: _pingResults = res #json.dumps(res) #log('Async PING results: %s' % _pingResults) finally: global _thread _thread = None
def _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite): """Execute program (MS Windows version)""" if not isinstance(args, types.StringTypes): args = list2cmdline(args) # Process startup details if startupinfo is None: startupinfo = STARTUPINFO() if None not in (p2cread, c2pwrite, errwrite): startupinfo.dwFlags |= STARTF_USESTDHANDLES startupinfo.hStdInput = p2cread startupinfo.hStdOutput = c2pwrite startupinfo.hStdError = errwrite if shell: startupinfo.dwFlags |= STARTF_USESHOWWINDOW startupinfo.wShowWindow = SW_HIDE comspec = os.environ.get("COMSPEC", "cmd.exe") args = comspec + " /c " + args if (GetVersion() >= 0x80000000L or os.path.basename(comspec).lower() == "command.com"): # Win9x, or using command.com on NT. We need to # use the w9xpopen intermediate program. For more # information, see KB Q150956 # (http://web.archive.org/web/20011105084002/http://support.microsoft.com/support/kb/articles/Q150/9/56.asp) w9xpopen = self._find_w9xpopen() args = '"%s" %s' % (w9xpopen, args) # Not passing CREATE_NEW_CONSOLE has been known to # cause random failures on win9x. Specifically a # dialog: "Your program accessed mem currently in # use at xxx" and a hopeful warning about the # stability of your system. Cost is Ctrl+C wont # kill children. creationflags |= CREATE_NEW_CONSOLE # We create a new job for this process, so that we can kill # the process and any sub-processes self._job = winprocess.CreateJobObject() creationflags |= winprocess.CREATE_SUSPENDED # Vista will launch Komodo in a job object itself, so we need # to specify that the created process is not part of the Komodo # job object, but instead specify that it will be using a # separate breakaway job object, bug 83001. creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB
def start(self): for x in self.env: os.environ[x] = self.env[x] try: self._cancel = Gio.Cancellable() if IS_WINDOWS: # Windows sinfo = STARTUPINFO() sinfo.dwFlags = STARTF_USESHOWWINDOW sinfo.wShowWindow = 0 cflags = nice_to_priority_class(self.priority) self._proc = Popen(self.cmdline, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=sinfo, creationflags=cflags) self._stdout = WinPopenReader(self._proc.stdout) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) elif HAS_SUBPROCESS: # New Gio flags = Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_MERGE if self.priority == 0: self._proc = Gio.Subprocess.new(self.cmdline, flags) else: # I just really do hope that there is no distro w/out nice command self._proc = Gio.Subprocess.new( ["nice", "-n", "%s" % self.priority] + self.cmdline, flags) self._proc.wait_check_async(None, self._cb_finished) self._stdout = self._proc.get_stdout_pipe() else: # Gio < 3.12 - Gio.Subprocess is missing :( if self.priority == 0: self._proc = Popen(self.cmdline, stdout=PIPE) else: # still hoping self._proc = Popen( ["nice", "-n", "%s" % self.priority], stdout=PIPE) self._stdout = Gio.UnixInputStream.new( self._proc.stdout.fileno(), False) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) except Exception as e: # Startup failed self.emit("failed", e) return self._lines = deque([], DaemonProcess.SCROLLBACK_SIZE) self._buffer = "" self._stdout.read_bytes_async(256, 0, self._cancel, self._cb_read, ())
def _pingAsyncWindows(self): args = 'ping -n 1 -w 1000 ' si = STARTUPINFO() si.dwFlags = STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE # Ping all servers in parallel processes = dict() for x in self.hosts: processes[x['name']] = Popen(args + x['url'].split(':')[0], stdout=PIPE, startupinfo=si) # pattern = '.*=.*=(\d+)[^\s].*=.*' # original pattern, working with russian, not with others pattern = '.*=.*=(\d+).*[^\s].*=.*' # fixed pattern, need testing but should work with every language return (pattern, processes)
def _pingAsyncWindows(self): args = 'ping -n 1 -w 1000 ' si = STARTUPINFO() si.dwFlags = STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE # Ping all servers in parallel processes = dict() for x in self.hosts: processes[x['name']] = Popen(args + x['url'].split(':')[0], stdout=PIPE, startupinfo=si) # ќтвет от 178.20.235.151: число байт=32 врем¤=23мс TTL=58 pattern = '.*=.*=(\d+)[^\s].*=.*' return (pattern, processes)
def popen(self): if debug: print("popen cmd: %s" % self.args) if self.dry_run: return startupinfo = None if self.hidden: from subprocess import STARTUPINFO, _winapi startupinfo = STARTUPINFO() startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW startupinfo.wShowWindow = _winapi.SW_HIDE subprocess.Popen(self.args[0] if len(self.args) == 1 else self.args, cwd=self.cwd, startupinfo=startupinfo)
def start(self): os.environ["STNORESTART"] = "1" # see syncthing --help os.environ["STNOUPGRADE"] = "1" # hopefully implemented later if self.max_cpus > 0: os.environ["GOMAXPROCS"] = str(self.max_cpus) try: self._cancel = Gio.Cancellable() if IS_WINDOWS: # Windows sinfo = STARTUPINFO() sinfo.dwFlags = STARTF_USESHOWWINDOW sinfo.wShowWindow = 0 cflags = nice_to_priority_class(self.priority) self._proc = Popen(self.commandline, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=sinfo, creationflags=cflags) self._stdout = WinPopenReader(self._proc) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) elif HAS_SUBPROCESS: # New Gio flags = Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_MERGE if self.priority == 0: self._proc = Gio.Subprocess.new(self.commandline, flags) else: # I just really do hope that there is no distro w/out nice command self._proc = Gio.Subprocess.new( ["nice", "-%s" % self.priority] + self.commandline, flags) self._proc.wait_check_async(None, self._cb_finished) self._stdout = self._proc.get_stdout_pipe() else: # Gio < 3.12 - Gio.Subprocess is missing :( if self.priority == 0: self._proc = Popen(self.commandline, stdout=PIPE) else: # still hoping self._proc = Popen(["nice", "-%s" % self.priority], stdout=PIPE) self._stdout = Gio.UnixInputStream.new( self._proc.stdout.fileno(), False) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) except Exception, e: # Startup failed self.emit("failed", e) return
def _open_subprocess(self, args, passphrase=False): # Internal method: open a pipe to a GPG subprocess and return # the file objects for communicating with it. cmd = self.make_args(args, passphrase) if self.verbose: pcmd = ' '.join(cmd) print(pcmd) logger.debug("%s", cmd) if not STARTUPINFO: si = None else: si = STARTUPINFO() si.dwFlags = STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE return Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=si)
def run_shell_command(args, input): # Hide console window on Windows. import sys if sys.platform == 'win32': from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW spinfo = STARTUPINFO() spinfo.dwFlags |= STARTF_USESHOWWINDOW else: spinfo = None from subprocess import Popen, PIPE try: p = Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=spinfo) except: return None, None, None # Use communicate() to read stdout and stderr without blocking. msout, mserr = p.communicate(input=input) # returns strings status = p.wait() return msout, mserr, status
def check_binary_exists(program_path): """ Function that checks whether a binary exists. :param pathlib.Path program_path: The full path to the binary to check. :return: program output to be parsed :rtype: bytes """ log.debug('testing program_path: {text}'.format(text=program_path)) try: # Setup startupinfo options for check_output to avoid console popping up on windows if is_win(): from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW else: startupinfo = None run_log = check_output([str(program_path), '--help'], stderr=STDOUT, startupinfo=startupinfo) except CalledProcessError as e: run_log = e.output except Exception: trace_error_handler(log) run_log = '' log.debug('check_output returned: {text}'.format(text=run_log)) return run_log
def run(self): fmt = self.fmt fromFilename = currentFilename toFilename = os.path.splitext(fromFilename)[0] + "." + fmt args = ["pandoc", fromFilename] if fmt == "pdf": args.extend(["--pdf-engine", "wkhtmltopdf"]) args.extend(["-o", toFilename]) try: from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW except: startupinfo = None process = Popen(args=args, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=startupinfo) err = process.communicate()[1].decode() code = process.returncode wnd.statusBar().showMessage(("转换成功: " + toFilename) if code == 0 else "转换失败: " + err) self.done.emit(True)
def _pingAsyncWindows(self): args = 'ping -n 1 -w 1000 ' si = STARTUPINFO() si.dwFlags = STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE # Ping all servers in parallel processes = dict() for x in self.hosts: processes[x['name']] = Popen(args + x['url'].split(':')[0], stdout=PIPE, startupinfo=si) # ќтвет от 178.20.235.151: число байт=32 врем¤=23мс TTL=58 #pattern = '.*=.*=(\d+)[^\s].*=.*' #original pattern, working with russian, not with others pattern = '.*=.*=(\d+).*[^\s].*=.*' #fixed pattern, need testing but should work with every language return (pattern, processes)
def connect_intercept(self): hostname = self.path.split(':')[0] certpath = "%s\\%s.crt" % (self.certdir.rstrip('\\'), hostname) with self.lock: if not os.path.isfile(certpath): startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW cert_generate(self.cakey, self.certkey, certpath, hostname) self.wfile.write("{} {} {}\r\n".format( self.protocol_version, 200, 'Connection Established').encode()) self.end_headers() try: self.connection = ssl.wrap_socket(self.connection, keyfile=self.certkey, certfile=certpath, server_side=True) except Exception as e: print(e) self.rfile = self.connection.makefile("rb", self.rbufsize) self.wfile = self.connection.makefile("wb", self.wbufsize) conntype = self.headers.get('Proxy-Connection', '') if self.protocol_version == "HTTP/1.1" and conntype.lower() != 'close': self.close_connection = 0 else: self.close_connection = 1
async def async_disconnect_all(_self, disconnect_array, sw_close): # timeout = float(_self.config["SETTINGS"]["connecting_timeout"]) # menu_box_spinner = QtWaitingSpinner(_self.menu_box, True, True, Qt.ApplicationModal) server_box_spinner = QtWaitingSpinner(_self.server_box, True, True, Qt.ApplicationModal) device_box_spinner = QtWaitingSpinner(_self.device_box, True, True, Qt.ApplicationModal) # config.spinner_queue.start_spinner( [menu_box_spinner, server_box_spinner, device_box_spinner]) _self.cancel_process.setParent(_self) _self.cancel_process.show() # Number of remaining devices array_length = config.get_array_length(disconnect_array) # for srv_addr in disconnect_array: for dev_bus in list(disconnect_array[srv_addr]): index = config.usbip_array[srv_addr][dev_bus]["d_index"] # Reducing the number of remaining devices array_length -= 1 # Eliminating windows console during process execution startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW # query = Popen("usbip.exe -d {0}".format(index), stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=startupinfo) query.wait() # config.logging_result.append_text( _self, _("The {0} device from the {1} server has disconnected, {2} left" ).format(dev_bus, srv_addr, str(array_length)), warn=True) # await sleep(timeout) # Stopping all running processes and shutdown the program if sw_close: for queue in all_tasks(_self.main_loop): queue.cancel() with suppress(CancelledError): await queue _self.main_loop.stop() # config.spinner_queue.stop_spinner( [menu_box_spinner, server_box_spinner, device_box_spinner]) _self.cancel_process.setParent(None)
async def convert_ardf(ardf_path, conv_path="ARDFtoHDF5.exe", pbar=None): """Turn an ARDF into a corresponding ARH5, returning the path. Requires converter executable available from Asylum Research""" ardf_path = trio.Path(ardf_path) h5file_path = ardf_path.with_suffix(".h5") if pbar is None: pipe = None else: pbar.set_description_str("Converting " + ardf_path.name) pipe = PIPE async def reading_stdout(): stdout = bytearray() async for bytes_ in proc.stdout: stdout.extend(bytes_) stdout = stdout.decode() if "Failed" in stdout: raise RuntimeError(stdout) else: print(stdout) async def reading_stderr(): async for bytes_ in proc.stderr: i = bytes_.rfind( b"\x08") + 1 # first thing on right not a backspace most_recent_numeric_output = bytes_[i:-1] # crop % sign if most_recent_numeric_output: pbar.update( float(most_recent_numeric_output.decode()) - pbar.n) try: async with await trio.open_process( [str(conv_path), str(ardf_path), str(h5file_path)], stderr=pipe, stdout=pipe, startupinfo=STARTUPINFO(dwFlags=STARTF_USESHOWWINDOW), ) as proc: if pbar is not None: async with trio.open_nursery() as nursery: nursery.start_soon(reading_stdout) nursery.start_soon(reading_stderr) except FileNotFoundError: raise FileNotFoundError( "Please acquire ARDFtoHDF5.exe and place it in the application's root folder." ) except: with trio.CancelScope(shield=True): await h5file_path.unlink(missing_ok=True) raise finally: if pbar is not None: pbar.close() return h5file_path
def start(self, cmd): si = STARTUPINFO() si.dwFlags |= STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE r, w = os.pipe() self.pipeout = r self.pipein = w self.proc = Popen(cmd, stdout=w, stderr=w, creationflags=CREATE_NEW_CONSOLE, startupinfo=si) sleep(0.5) print '[*] pid: ', hex(self.proc.pid) self.Console_hwnd = get_hwnds_for_pid(self.proc.pid) print '[*] hwnd:', self.Console_hwnd[0]
def get_angles(location): startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW output, _ = Popen( ["python", "inverse_kinematics.py", str(location[0]), str(location[1]), str(location[2])], stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=startupinfo).communicate() return str(output).split(" ")
def _spawn_windows(cmd, env): from subprocess import STARTF_USESHOWWINDOW, STARTUPINFO creationflags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW _popen(cmd, env=env, creationflags=creationflags, startupinfo=startupinfo).communicate()
def start(self): for x in self.env: os.environ[x] = self.env[x] try: self._cancel = Gio.Cancellable() if IS_WINDOWS: # Windows sinfo = STARTUPINFO() sinfo.dwFlags = STARTF_USESHOWWINDOW sinfo.wShowWindow = 0 cflags = nice_to_priority_class(self.priority) self._proc = Popen(self.cmdline, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=sinfo, creationflags=cflags) self._stdout = WinPopenReader(self._proc.stdout) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) elif HAS_SUBPROCESS: # New Gio flags = Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_MERGE if self.priority == 0: self._proc = Gio.Subprocess.new(self.cmdline, flags) else: # I just really do hope that there is no distro w/out nice command self._proc = Gio.Subprocess.new([ "nice", "-n", "%s" % self.priority ] + self.cmdline, flags) self._proc.wait_check_async(None, self._cb_finished) self._stdout = self._proc.get_stdout_pipe() else: # Gio < 3.12 - Gio.Subprocess is missing :( if self.priority == 0: self._proc = Popen(self.cmdline, stdout=PIPE) else: # still hoping self._proc = Popen([ "nice", "-n", "%s" % self.priority ], stdout=PIPE) self._stdout = Gio.UnixInputStream.new(self._proc.stdout.fileno(), False) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) except Exception as e: # Startup failed self.emit("failed", e) return self._lines = deque([], DaemonProcess.SCROLLBACK_SIZE) self._buffer = "" self._stdout.read_bytes_async(256, 0, self._cancel, self._cb_read, ())
async def __call__(self, url: str) -> None: if self.arguments is None: await logging.info(f'Launching {url!r} with default program') await open_with_default_application(url) else: arguments = list(self.subbed_arguments(url)) startupinfo: Optional[STARTUPINFO] if WINDOWS: startupinfo = STARTUPINFO() startupinfo.dwFlags = STARTF_USESHOWWINDOW else: startupinfo = None await logging.info( f'Launching subprocess with arguments {arguments}' ) await run_subprocess( args=arguments, startupinfo=startupinfo )
def start(self): os.environ["STNORESTART"] = "1" # see syncthing --help os.environ["STNOUPGRADE"] = "1" # hopefully implemented later if self.max_cpus > 0: os.environ["GOMAXPROCS"] = str(self.max_cpus) try: self._cancel = Gio.Cancellable() if IS_WINDOWS: # Windows sinfo = STARTUPINFO() sinfo.dwFlags = STARTF_USESHOWWINDOW sinfo.wShowWindow = 0 cflags = nice_to_priority_class(self.priority) self._proc = Popen(self.commandline, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=sinfo, creationflags=cflags) self._stdout = WinPopenReader(self._proc.stdout) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) else: cmdline = self.commandline if self.iopriority != 0: cmdline = [ "ionice", "-c", "%s" % self.iopriority ] + cmdline if self.priority != 0: # I just really do hope that there is no distro w/out nice command cmdline = [ "nice", "-n", "%s" % self.priority ] + cmdline print cmdline if HAS_SUBPROCESS: # New Gio flags = Gio.SubprocessFlags.STDOUT_PIPE | Gio.SubprocessFlags.STDERR_MERGE self._proc = Gio.Subprocess.new(cmdline, flags) self._proc.wait_check_async(None, self._cb_finished) self._stdout = self._proc.get_stdout_pipe() else: # Gio < 3.12 - Gio.Subprocess is missing :( self._proc = Popen(cmdline, stdout=PIPE) self._stdout = Gio.UnixInputStream.new(self._proc.stdout.fileno(), False) self._check = GLib.timeout_add_seconds(1, self._cb_check_alive) except Exception, e: # Startup failed self.emit("failed", e) return
def run_engine(slice_message: Slice, event_handler, child_started_handler=None, keep_alive_handler=None): with open(engine_log_file, 'a+') as log_file: print(datetime.now(), file=log_file, flush=True) encoded_message = Slice.dumps(slice_message) config = read_configuration() print(dict(config), file=log_file, flush=True) with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as server_socket: server_socket.bind(('127.0.0.1', 0)) server_socket.listen(5) name = server_socket.getsockname() extra_params = {} if os.name == 'nt': from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW info = STARTUPINFO() info.dwFlags |= STARTF_USESHOWWINDOW extra_params['startupinfo'] = info cmd = ' '.join(['"' + config['curaengine'] + '"', 'connect', "%s:%s" % name, '-j', '"' + fdmprinterfile + '"']) print(cmd, file=log_file, flush=True) child_process = Popen(cmd, stdout=log_file, stderr=log_file, **extra_params, shell=True) if child_started_handler: child_started_handler(child_process) try: print(child_process, file=log_file, flush=True) print(child_process.poll(), file=log_file, flush=True) (client_socket, address) = server_socket.accept() client_socket.send(struct.pack("I", socket.htonl(_SIGNATURE))) client_socket.send(struct.pack("!I", len(encoded_message))) client_socket.send(struct.pack("!I", symbol_message_dict['cura.proto.Slice'].hash)) client_socket.send(encoded_message) while 1: process = client_socket.recv(4) if len(process) == 4: unpacked = struct.unpack('>I', process)[0] if unpacked == 0: if keep_alive_handler: keep_alive_handler() continue if unpacked == _CLOSE_SOCKET: print('_CLOSE_SOCKET') return if unpacked == _SIGNATURE: size = struct.unpack('>I', client_socket.recv(4))[0] type_id = struct.unpack('>I', client_socket.recv(4))[0] type_def = hash_message_dict[type_id] res3 = recvall(client_socket, size) if size else b'' event_handler(res3, type_def) continue break else: break finally: print(child_process.communicate(), file=log_file, flush=True)
def Popen(*args, show='normal', priority=2, **kwargs): if os.name == 'nt': if isinstance(show, str): show = WINDOW_STATES[show] if show != 1: startupinfo = kwargs.get('startupinfo', STARTUPINFO()) startupinfo.dwFlags |= 1 #subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = show kwargs['startupinfo'] = startupinfo kwargs['creationflags'] = kwargs.get('creationflags', 0) | PROCESS_PRIORITIES[priority] return Popen_original(*args, **kwargs)
def start_local(arch='x86', path=None): '''start the wdbg subprocess, and return its listened port''' path = path or search_wdbg(arch) if not path: return None from subprocess import STARTUPINFO, SW_HIDE, PIPE from subprocess import CREATE_NEW_CONSOLE, STARTF_USESHOWWINDOW from subprocess import SubprocessError, Popen si = STARTUPINFO() si.dwFlags = STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE try: return Popen([path, '-D', '-a', '127.0.0.1'], bufsize=0, startupinfo=si, stdin=PIPE, creationflags=CREATE_NEW_CONSOLE, stdout=PIPE) except SubprocessError: return None
def _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite): """Execute program (MS Windows version)""" if not isinstance(args, str): args = list2cmdline(args) # Process startup details if startupinfo is None: startupinfo = STARTUPINFO() if None not in (p2cread, c2pwrite, errwrite): startupinfo.dwFlags |= STARTF_USESTDHANDLES startupinfo.hStdInput = p2cread startupinfo.hStdOutput = c2pwrite startupinfo.hStdError = errwrite if shell: startupinfo.dwFlags |= STARTF_USESHOWWINDOW startupinfo.wShowWindow = SW_HIDE comspec = os.environ.get("COMSPEC", "cmd.exe") args = comspec + " /c " + args if (GetVersion() >= 0x80000000 or os.path.basename(comspec).lower() == "command.com"): # Win9x, or using command.com on NT. We need to # use the w9xpopen intermediate program. For more # information, see KB Q150956 # (http://web.archive.org/web/20011105084002/http://support.microsoft.com/support/kb/articles/Q150/9/56.asp) w9xpopen = self._find_w9xpopen() args = '"%s" %s' % (w9xpopen, args) # Not passing CREATE_NEW_CONSOLE has been known to # cause random failures on win9x. Specifically a # dialog: "Your program accessed mem currently in # use at xxx" and a hopeful warning about the # stability of your system. Cost is Ctrl+C wont # kill children. creationflags |= CREATE_NEW_CONSOLE # We create a new job for this process, so that we can kill # the process and any sub-processes self._job = winprocess.CreateJobObject() creationflags |= winprocess.CREATE_SUSPENDED # Vista will launch Komodo in a job object itself, so we need # to specify that the created process is not part of the Komodo # job object, but instead specify that it will be using a # separate breakaway job object, bug 83001. creationflags |= winprocess.CREATE_BREAKAWAY_FROM_JOB # Start the process try: hp, ht, pid, tid = CreateProcess(executable, args, # no special security None, None, int(not close_fds), creationflags, env, cwd, startupinfo) except pywintypes.error as e: # Translate pywintypes.error to WindowsError, which is # a subclass of OSError. FIXME: We should really # translate errno using _sys_errlist (or simliar), but # how can this be done from Python? raise WindowsError(*e.args) except WindowsError: log.error( "process.py: can't execute %r (%s)", executable, args) raise # Retain the process handle, but close the thread handle self._child_created = True self._handle = hp self.pid = pid if self._job: # Resume the thread. winprocess.AssignProcessToJobObject(self._job, int(hp)) winprocess.ResumeThread(int(ht)) ht.Close() # Child is launched. Close the parent's copy of those pipe # handles that only the child should have open. You need # to make sure that no handles to the write end of the # output pipe are maintained in this process or else the # pipe will not close when the child process exits and the # ReadFile will hang. if p2cread is not None: p2cread.Close() if c2pwrite is not None: c2pwrite.Close() if errwrite is not None: errwrite.Close()
def bpgdecode(self,filename): msg=None cmd=self.bpgpath+' -o ' if self.img: del self.img self.img=None if len(filename)>4 and filename[-4:].lower()=='.bpg': try: if not(isfile(filename) and access(filename,R_OK)): msg=_('Unable to open')+'\"%s\"!'%filename except: return False if not(msg): err=0 try: imbuffer='' if osflag: fifo=osopen(self.fifo,O_RDONLY|O_NONBLOCK) cmd+=self.fifo+' "'+realpath(filename)+'"'+\ ' >/dev/null 2>&1' f=Popen(cmd,shell=True,stdin=None,stdout=None,\ stderr=None) if fifo: while True: if f.poll()!=None: break; try: data=osread(fifo,16777216) except OSError as e: if e.errno==errno.EAGAIN or\ e.errno==errno.EWOULDBLOCK: data='' else: raise if len(data): imbuffer+=data osclose(fifo) else: si=STARTUPINFO() si.dwFlags|=1 si.wShowWindow=0 pname='\\\\.\\pipe\\'+basename(self.fifo) tpipe=win32pipe.CreateNamedPipe( pname, win32pipe.PIPE_ACCESS_DUPLEX, win32pipe.PIPE_TYPE_BYTE|win32pipe.PIPE_WAIT, 1,16777216,16777216,2000,None) cmd+=pname+' "'+realpath(filename)+'"' f=Popen(cmd,shell=False,stdin=None,stdout=None,\ stderr=None,bufsize=0,startupinfo=si) win32pipe.ConnectNamedPipe(tpipe,None) imbuffer='' if tpipe: while True: data=None try: data=win32file.ReadFile(tpipe,16777216) except: data=None if not(data): break if data[0]!=0: break if len(data[1]): imbuffer+=data[1] win32pipe.DisconnectNamedPipe(tpipe) f.wait() if len(imbuffer): if imbuffer[0]=='a': mode='RGBA' else: mode='RGB' x,=unpack("i",imbuffer[1:5]) y,=unpack("i",imbuffer[5:9]) try: self.img=Image.fromstring(mode,(x,y),imbuffer[9:]) except: err=1 del imbuffer else: err=1 except: err=1 if err: msg=_('BPG decoding error!\n') else: msg=_('File')+' \"%s\" '%filename+_('is not a BPG-File!') if msg: print msg errmsgbox(msg) if self.img: del self.img self.img=None else: return True return False
import requests from bs4 import BeautifulSoup as bs from datetime import datetime from subprocess import Popen, STARTUPINFO '''Path for the file to be written''' FILE_PATH = 'E:\\Documents\\promocoes.txt' BACKUP_FILE_PATH = 'E:\Documents\\promocoes_backup.txt' '''Start up options for process wShowWindow = 0 -> hidden''' start_info = STARTUPINFO() start_info.dwFlags = 1 start_info.wShowWindow = 1 '''current time''' time = datetime.now() def get_html_cloudfare(link): scraper = cfscrape.create_scraper() return scraper.get(link).content def get_title(soup): return soup.title.encode('utf-8')
def CmdTask(args=[], workdir=None): currdir = None if workdir: currdir = os.getcwdu() os.chdir(workdir) si = None if os.name != 'posix': from subprocess import STARTUPINFO si = STARTUPINFO() si.dwFlags |= STARTF_USESHOWWINDOW si.wShowWindow = SW_HIDE popen_args = { 'args': args, 'stdout': PIPE, 'stderr': STDOUT, 'universal_newlines': True, 'startupinfo': si, 'shell': False, # mencoder cannot be terminated if shell is True } code = 0 buf = StringIO() pos = 0 p = Popen(**popen_args) try: cmdline = ' '.join(args) (yield TaskOutput('START: {} ...'.format(cmdline))) if popen_args['universal_newlines']: while True: line = p.stdout.readline() if line == "": break if not (yield TaskOutput(line, OutputType.OUTPUT)): raise CommandTerminated() else: lastline = "" while True: line = p.stdout.read(512) if line == "": break buf.seek(0) buf.write(line.replace("\r", "\n")) buf.seek(0) while True: l = buf.readline() if not l.endswith("\n"): lastline = l break outline = lastline+l.rstrip() lastline = "" if outline == "": continue if not (yield TaskOutput(outline, OutputType.OUTPUT)): raise CommandTerminated() (yield TaskOutput('END: {} ...'.format(args[0]))) except CommandTerminated: code = -2 (yield TaskOutput('TERMINITED: {}'.format(args[0]), OutputType.WARN)) try: p.terminate() p.wait() except: pass except Exception as ex: code = -1 errmsg = ex.message or ex.args[-1] (yield TaskOutput(errmsg, OutputType.ERROR)) finally: buf.close() if currdir: os.chdir(currdir) (yield TaskOutput('EXIT {}'.format(code), OutputType.NOTIFY))
def bpgdecode(self,filename): msg=None cmd=self.bpgpath self.frames_index=0 if len(self.frames): self.frames=[] if self.img: del self.img self.img=None if len(filename)>4 and filename[-4:].lower()=='.bpg': try: if not(isfile(filename) and access(filename,R_OK)): msg=_('Unable to open')+'\"%s\"!'%filename except: return False if not(msg): err=0 try: imbuffer='' if osflag: fifo=osopen(self.fifo,O_RDONLY|O_NONBLOCK) cmd+=' "'+realpath(filename)+'" '+self.fifo+\ ' >/dev/null 2>&1' f=Popen(cmd,shell=True,stdin=None,stdout=None,\ stderr=None) if fifo: while True: if f.poll()!=None: break; try: data=osread(fifo,16777216) except OSError as e: if e.errno==errno.EAGAIN or\ e.errno==errno.EWOULDBLOCK: data='' else: raise if len(data): imbuffer+=data osclose(fifo) else: si=STARTUPINFO() si.dwFlags|=1 si.wShowWindow=0 pname='\\\\.\\pipe\\'+basename(self.fifo) tpipe=win32pipe.CreateNamedPipe( pname, win32pipe.PIPE_ACCESS_DUPLEX, win32pipe.PIPE_TYPE_BYTE|win32pipe.PIPE_WAIT, 1,16777216,16777216,2000,None) cmd+=' "'+realpath(filename)+'" '+pname f=Popen(cmd,shell=False,stdin=None,stdout=None,\ stderr=None,bufsize=0,startupinfo=si) win32pipe.ConnectNamedPipe(tpipe,None) imbuffer='' if version_info[0]<3: imbuffer='' else: imbuffer=b'' if tpipe: while True: data=None try: data=win32file.ReadFile(tpipe,16777216) except: data=None if not(data): break if data[0]!=0: break if len(data[1]): imbuffer+=data[1] win32pipe.DisconnectNamedPipe(tpipe) f.wait() if len(imbuffer): x,=unpack("i",imbuffer[0:4]) y,=unpack("i",imbuffer[4:8]) n,=unpack("i",imbuffer[8:12]) d,=unpack("i",imbuffer[12:16]) if n==0 and d==1: try: self.img=Image.frombytes('RGBA',(x,y), imbuffer[16:]) except: err=1 else: self.scale=100.0 self.autoscale=self.scale self.bitmap_text=str(x)+'x'+str(y) self.imginfo='%.2f'%self.scale+'%@'+self.bitmap_text ishift=8 dr=n*1000/d while True: try: n,=unpack("i",imbuffer[ishift:ishift+4]) ishift+=4 d,=unpack("i",imbuffer[ishift:ishift+4]) ishift+=4 except: break try: img=Image.frombytes('RGBA',(x,y), imbuffer[ishift:]) except: break ishift+=(x*y*4) self.frames.append([self.bitmapfrompil(img),n*1000/d]) else: err=1 del imbuffer else: err=1 except: err=1 if err: msg=_('BPG decoding error!\n') else: msg=_('File')+' \"%s\" '%filename+_('is not a BPG-File!') if msg: wx.PostEvent(self,ShowEvent(SE_EVT_TYPE,-1,value=msg)) if self.img: del self.img self.img=None else: return True return False
__all__ = ( 'check_output', ) _l = Logger.from_module(__name__) if sys.platform == 'win32': import ctypes from subprocess import STARTUPINFO from subprocess import STARTF_USESHOWWINDOW from subprocess import SW_HIDE startup_info = STARTUPINFO() startup_info.dwFlags = STARTF_USESHOWWINDOW | SW_HIDE def _check_output(args, shell=False, universal_newlines=False, timeout=None): """Conveniently read a process's output on Windows. Supresses the console window and decodes the binary stream using the console's codepage. """ # universal_newlines causes the output to be interpreted as `locale.getpreferredencoding()`, # which doesn't work at times because console (OEM?) applications usually use a different # encoding instead. For example, 850 for Western Europe, 437 for English and 936 for Chinese. proc = Popen(args, stdout=PIPE, stderr=PIPE, shell=shell, universal_newlines=False, startupinfo=startup_info) data, err = proc.communicate(timeout=timeout)