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 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 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 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 _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 _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 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) # ќтвет от 178.20.235.151: число байт=32 врем¤=23мс TTL=58 pattern = '.*=.*=(\d+)[^\s].*=.*' 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) # 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 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 _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 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 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 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 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 encode_chunk(self, thread_id: str, file: Wave_read, total_samples_to_read: int, output: BytesIO) -> None: options = STARTUPINFO() options.dwFlags |= subprocess.STARTF_USESHOWWINDOW options.wShowWindow = subprocess.SW_HIDE process = Popen(self.command, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=options) read_data_thread = Thread( target=lambda: output.write(process.stdout.read())) read_data_thread.daemon = True read_data_thread.start() samples_to_read, samples_left = self.update_samples_to_read( total_samples_to_read, 1024) last_progress = 0 while samples_left > 0: process.stdin.write(file.readframes(samples_to_read)) progress = int((total_samples_to_read - samples_left) * 100 / total_samples_to_read) if progress != last_progress: self.listener.encode_update(thread_id, progress) last_progress = progress samples_to_read, samples_left = self.update_samples_to_read( samples_left, 1024) self.listener.encode_update(thread_id, 100) process.stdin.close() read_data_thread.join() process.stdout.close() process.stderr.close() file.close()
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
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 ssh_exec_connect_to(display_desc, opts=None, debug_cb=None, ssh_fail_cb=ssh_connect_failed): if not ssh_fail_cb: ssh_fail_cb = ssh_connect_failed sshpass_command = None try: cmd = list(display_desc["full_ssh"]) kwargs = {} env = display_desc.get("env") kwargs["stderr"] = sys.stderr if WIN32: from subprocess import CREATE_NEW_PROCESS_GROUP, CREATE_NEW_CONSOLE, STARTUPINFO, STARTF_USESHOWWINDOW startupinfo = STARTUPINFO() startupinfo.dwFlags |= STARTF_USESHOWWINDOW startupinfo.wShowWindow = 0 #aka win32.con.SW_HIDE flags = CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE kwargs.update({ "startupinfo" : startupinfo, "creationflags" : flags, "stderr" : PIPE, }) elif not display_desc.get("exit_ssh", False) and not OSX: kwargs["start_new_session"] = True remote_xpra = display_desc["remote_xpra"] assert remote_xpra socket_dir = display_desc.get("socket_dir") proxy_command = display_desc["proxy_command"] #ie: "_proxy_start" display_as_args = display_desc["display_as_args"] #ie: "--start=xterm :10" remote_cmd = "" for x in remote_xpra: if not remote_cmd: check = "if" else: check = "elif" if x=="xpra": #no absolute path, so use "which" to check that the command exists: pc = ['%s which "%s" > /dev/null 2>&1; then' % (check, x)] else: pc = ['%s [ -x %s ]; then' % (check, x)] pc += [x] + proxy_command + [shellquote(x) for x in display_as_args] if socket_dir: pc.append("--socket-dir=%s" % socket_dir) remote_cmd += " ".join(pc)+";" remote_cmd += "else echo \"no run-xpra command found\"; exit 1; fi" if INITENV_COMMAND: remote_cmd = INITENV_COMMAND + ";" + remote_cmd #how many times we need to escape the remote command string #depends on how many times the ssh command is parsed nssh = sum(int(x=="ssh") for x in cmd) if nssh>=2 and MAGIC_QUOTES: for _ in range(nssh): remote_cmd = shlex.quote(remote_cmd) else: remote_cmd = "'%s'" % remote_cmd cmd.append("sh -c %s" % remote_cmd) if debug_cb: debug_cb("starting %s tunnel" % str(cmd[0])) #non-string arguments can make Popen choke, #instead of lazily converting everything to a string, we validate the command: for x in cmd: if not isinstance(x, str): raise InitException("argument is not a string: %s (%s), found in command: %s" % (x, type(x), cmd)) password = display_desc.get("password") if password and not display_desc.get("is_putty", False): from xpra.platform.paths import get_sshpass_command sshpass_command = get_sshpass_command() if sshpass_command: #sshpass -e ssh ... cmd.insert(0, sshpass_command) cmd.insert(1, "-e") if env is None: env = os.environ.copy() env["SSHPASS"] = password #the password will be used by ssh via sshpass, #don't try to authenticate again over the ssh-proxy connection, #which would trigger warnings if the server does not require #authentication over unix-domain-sockets: opts.password = None del display_desc["password"] if env: kwargs["env"] = env if is_debug_enabled("ssh"): log.info("executing ssh command: %s" % (" ".join("\"%s\"" % x for x in cmd))) child = Popen(cmd, stdin=PIPE, stdout=PIPE, **kwargs) except OSError as e: raise InitExit(EXIT_SSH_FAILURE, "Error running ssh command '%s': %s" % (" ".join("\"%s\"" % x for x in cmd), e)) def abort_test(action): """ if ssh dies, we don't need to try to read/write from its sockets """ e = child.poll() if e is not None: had_connected = conn.input_bytecount>0 or conn.output_bytecount>0 if had_connected: error_message = "cannot %s using SSH" % action else: error_message = "SSH connection failure" sshpass_error = None if sshpass_command: sshpass_error = { 1 : "Invalid command line argument", 2 : "Conflicting arguments given", 3 : "General runtime error", 4 : "Unrecognized response from ssh (parse error)", 5 : "Invalid/incorrect password", 6 : "Host public key is unknown. sshpass exits without confirming the new key.", }.get(e) if sshpass_error: error_message += ": %s" % sshpass_error if debug_cb: debug_cb(error_message) if ssh_fail_cb: ssh_fail_cb(error_message) if "ssh_abort" not in display_desc: display_desc["ssh_abort"] = True if not had_connected: log.error("Error: SSH connection to the xpra server failed") if sshpass_error: log.error(" %s", sshpass_error) else: log.error(" check your username, hostname, display number, firewall, etc") display_name = display_desc["display_name"] log.error(" for server: %s", display_name) else: log.error("The SSH process has terminated with exit code %s", e) cmd_info = " ".join(display_desc["full_ssh"]) log.error(" the command line used was:") log.error(" %s", cmd_info) raise ConnectionClosedException(error_message) from None def stop_tunnel(): if POSIX: #on posix, the tunnel may be shared with other processes #so don't kill it... which may leave it behind after use. #but at least make sure we close all the pipes: for name,fd in { "stdin" : child.stdin, "stdout" : child.stdout, "stderr" : child.stderr, }.items(): try: if fd: fd.close() except Exception as e: print("error closing ssh tunnel %s: %s" % (name, e)) if not display_desc.get("exit_ssh", False): #leave it running return try: if child.poll() is None: child.terminate() except Exception as e: print("error trying to stop ssh tunnel process: %s" % e) host = display_desc["host"] port = display_desc.get("ssh-port", 22) username = display_desc.get("username") display = display_desc.get("display") info = { "host" : host, "port" : port, } from xpra.net.bytestreams import TwoFileConnection conn = TwoFileConnection(child.stdin, child.stdout, abort_test, target=(host, port), socktype="ssh", close_cb=stop_tunnel, info=info) conn.endpoint = host_target_string("ssh", username, host, port, display) conn.timeout = 0 #taken care of by abort_test conn.process = (child, "ssh", cmd) if kwargs.get("stderr")==PIPE: def stderr_reader(): errs = [] while child.poll() is None: try: v = child.stderr.readline() except OSError: log("stderr_reader()", exc_info=True) break if not v: log("SSH EOF on stderr of %s", cmd) break s = bytestostr(v.rstrip(b"\n\r")) if s: errs.append(s) if errs: log.warn("remote SSH stderr:") for e in errs: log.warn(" %s", e) start_thread(stderr_reader, "ssh-stderr-reader", daemon=True) return conn
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 _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()
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 _get_startupinfo(self): from subprocess import STARTF_USESHOWWINDOW, SW_HIDE, STARTUPINFO result = STARTUPINFO() result.dwFlags = STARTF_USESHOWWINDOW result.wShowWindow = SW_HIDE return result
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
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()