Beispiel #1
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
Beispiel #2
0
 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)
Beispiel #3
0
    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
Beispiel #4
0
 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)
Beispiel #5
0
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 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()
Beispiel #7
0
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
Beispiel #8
0
    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
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
Beispiel #10
0
    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
Beispiel #11
0
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)
Beispiel #12
0
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 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(" ")
Beispiel #14
0
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()
Beispiel #15
0
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 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 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)
Beispiel #18
0
    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()
Beispiel #19
0
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
Beispiel #20
0
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
Beispiel #21
0
def _spawn_windows(cmd):
    from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW

    creationflags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS

    startupinfo = STARTUPINFO()
    startupinfo.dwFlags |= STARTF_USESHOWWINDOW

    Popen(cmd,
          env=fix_env(),
          close_fds=True,
          shell=False,
          creationflags=creationflags,
          startupinfo=startupinfo).communicate()
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 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, ())
Beispiel #24
0
def process_image(imagename,resultname,params="--edge-thresh 10 --peak-thresh 5"):
	""" Process an image and save the results in a file. """
	if imagename[-3:] != 'pgm':
		# create a pgm file
		im = Image.open(imagename).convert('L')
		im.save('tmp.pgm')
		imagename = 'tmp.pgm'

        # run the sift.exe file
	cmmd = str("sift "+imagename+" --output="+resultname+" "+params)
	if os.name == 'nt':     # only on windows
		startupinfo = STARTUPINFO()
		startupinfo.dwFlags |= STARTF_USESHOWWINDOW
	p = Popen(cmmd, stdout = PIPE, startupinfo=startupinfo) # run sift.exe in subprocess (no separate window opens)
	p.wait() # wait until subprocess finished
Beispiel #25
0
    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)
Beispiel #26
0
def _spawn_windows(cmd, env):
    from subprocess import (
        CREATE_NEW_PROCESS_GROUP,
        STARTF_USESHOWWINDOW,
        STARTUPINFO,
    )

    # https://stackoverflow.com/a/7006424
    # https://bugs.python.org/issue41619
    creationflags = CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW

    startupinfo = STARTUPINFO()
    startupinfo.dwFlags |= STARTF_USESHOWWINDOW

    _popen(cmd, env=env, creationflags=creationflags, startupinfo=startupinfo)
Beispiel #27
0
 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
Beispiel #28
0
        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
Beispiel #29
0
    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)
Beispiel #30
0
 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)