Python subprocess.STARTF_USESHOWWINDOW Examples
The following are 30
code examples of subprocess.STARTF_USESHOWWINDOW().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
subprocess
, or try the search function
.
Example #1
Source File: standard-format.py From sublime-standard-format with MIT License | 10 votes |
def command_version(command): """ Uses subprocess to format a given string. """ startupinfo = None if platform == "windows": # Prevent cmd.exe window from popping up startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= ( subprocess.STARTF_USESTDHANDLES | subprocess.STARTF_USESHOWWINDOW ) startupinfo.wShowWindow = subprocess.SW_HIDE std = subprocess.Popen( [command, "--version"], env=calculate_env(), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo ) out, err = std.communicate() return out.decode("utf-8").replace("\r", ""), err
Example #2
Source File: util.py From sublime-GitConflictResolver with MIT License | 6 votes |
def execute_command(command, working_dir=None): startupinfo = None # hide console window on windows if os.name == 'nt': startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW output = None try: output = subprocess.check_output( command, cwd=working_dir, startupinfo=startupinfo ) except (subprocess.CalledProcessError, AttributeError): # Git will return an error when the given directory # is not a repository, which means that we can ignore this error pass else: output = str(output, encoding="utf-8").strip() return output
Example #3
Source File: _utils.py From adbutils with MIT License | 6 votes |
def _popen_kwargs(prevent_sigint=False): startupinfo = None preexec_fn = None creationflags = 0 if sys.platform.startswith("win"): # Stops executable from flashing on Windows (see imageio/imageio-ffmpeg#22) startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW if prevent_sigint: # Prevent propagation of sigint (see imageio/imageio-ffmpeg#4) # https://stackoverflow.com/questions/5045771 if sys.platform.startswith("win"): creationflags = 0x00000200 else: preexec_fn = os.setpgrp # the _pre_exec does not seem to work return { "startupinfo": startupinfo, "creationflags": creationflags, "preexec_fn": preexec_fn, }
Example #4
Source File: aria2_downloader.py From kano-burners with GNU General Public License v2.0 | 6 votes |
def __init__(self, url, dest, progress_bar=False): self.url = url self.dest = dest self.hash_type = None self.hash_value = None self.process = None self.secret = ''.join(format(ord(x), 'x') for x in os.urandom(10)) self.gid = 'DEADC0D9BEEFFACE' self.status = None self.failed = False self.failure = None self.ariaStatus = {} self.gid = None if platform.system()=='Darwin': self.aria_stdout = None self.startupinfo = None else: self.aria_stdout = None self.startupinfo = subprocess.STARTUPINFO() self.startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW self.startupinfo.wShowWindow = subprocess.SW_HIDE
Example #5
Source File: runInIndesign.py From RunInIndesign with MIT License | 6 votes |
def __init__(self, shell_cmd): if not shell_cmd: raise ValueError("shell_cmd is required") if shell_cmd and not isinstance(shell_cmd, str): raise ValueError("shell_cmd must be a string") self.killed = False # Hide the console window on Windows startupinfo = None if os.name == "nt": startupinfo = subprocess.STARTUPINFO() #startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW print (shell_cmd) if sys.platform == "win32": # Use shell=True on Windows, so shell_cmd is passed through with the correct escaping self.proc = subprocess.Popen(shell_cmd, startupinfo=startupinfo, shell=True) elif shell_cmd and sys.platform == "darwin": # Use a login shell on OSX, otherwise the users expected env vars won't be setup self.proc = subprocess.Popen(["/bin/bash", "-l", "-c", shell_cmd], startupinfo=startupinfo, shell=False) self.proc.wait()
Example #6
Source File: QgsFmvUtils.py From QGISFMV with GNU General Public License v3.0 | 6 votes |
def run(self): if self.type is "ffmpeg": self.cmds.insert(0, ffmpeg_path) else: self.cmds.insert(0, ffprobe_path) qgsu.showUserAndLogMessage("", "starting Splitter on thread:" + str(threading.current_thread().ident), onlyLog=True) qgsu.showUserAndLogMessage("", "with args:" + ' '.join(self.cmds), onlyLog=True) # Hide shell windows that pops up on windows. if windows: startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE self.p = subprocess.Popen(self.cmds, startupinfo=startupinfo, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE) # Dont us _spawn here as it will DeadLock, and the splitter won't work #self.p = _spawn(self.cmds) self.nbsr = NonBlockingStreamReader(self.p) self.nbsr._t.join() qgsu.showUserAndLogMessage("", "Splitter thread ended.", onlyLog=True)
Example #7
Source File: fs_whatsapp.py From MR with MIT License | 6 votes |
def run(cmd): if sys.platform == 'win32': startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW else: startupinfo = None p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, startupinfo=startupinfo) #logtext.insert(END, "Cmd>") #for s in cmd: # logtext.insert(END, " " + s) #logtext.insert(END, "\r\n") stdout = '' while True: line = str(p.stdout.readline(), encoding='UTF-8') stdout += line #logtext.insert(END, line) #logtext.yview(END) curstat = p.poll() if ((line == '') and (curstat != None)): break return stdout
Example #8
Source File: vmrun.py From mech with MIT License | 6 votes |
def get_provider(vmrun_exe): """ identifies the right hosttype for vmrun command (ws | fusion | player) """ if sys.platform == 'darwin': return 'fusion' for provider in ['ws', 'player', 'fusion']: try: startupinfo = None if os.name == "nt": startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW proc = subprocess.Popen([vmrun_exe, '-T', provider, 'list'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo) except OSError: pass stdoutdata, stderrdata = map(b2s, proc.communicate()) if proc.returncode == 0: return provider
Example #9
Source File: utils.py From mech with MIT License | 6 votes |
def tar_cmd(*args, **kwargs): try: startupinfo = None if os.name == "nt": startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW proc = subprocess.Popen(['tar', '--help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo) except OSError: return None if proc.returncode: return None stdoutdata, stderrdata = map(b2s, proc.communicate()) tar = ['tar'] if kwargs.get('wildcards') and re.search(r'--wildcards\b', stdoutdata): tar.append('--wildcards') if kwargs.get('force_local') and re.search(r'--force-local\b', stdoutdata): tar.append('--force-local') if kwargs.get('fast_read') and sys.platform.startswith('darwin'): tar.append('--fast-read') tar.extend(args) return tar
Example #10
Source File: ghhelper.py From CityEnergyAnalyst with MIT License | 6 votes |
def run_cli(script_name, **parameters): """Run the CLI in a subprocess without showing windows""" startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW command = [get_python_exe(), '-u', '-m', 'cea.interfaces.cli.cli', script_name] for parameter_name, parameter_value in parameters.items(): parameter_name = parameter_name.replace('_', '-') command.append('--' + parameter_name) command.append(str(parameter_value)) print('Executing: ' + ' '.join(command)) process = subprocess.Popen(command, startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=tempfile.gettempdir()) while True: next_line = process.stdout.readline() if next_line == '' and process.poll() is not None: break print(next_line.rstrip()) stdout, stderr = process.communicate() print(stdout) print(stderr) if process.returncode != 0: raise Exception('Tool did not run successfully')
Example #11
Source File: internal.py From cryptolens-python with MIT License | 6 votes |
def subprocess_args(include_stdout=True): if hasattr(subprocess, 'STARTUPINFO'): si = subprocess.STARTUPINFO() si.dwFlags |= subprocess.STARTF_USESHOWWINDOW env = os.environ else: si = None env = None if include_stdout: ret = {'stdout': subprocess.PIPE} else: ret = {} ret.update({'stdin': subprocess.PIPE, 'stderr': subprocess.PIPE, 'startupinfo': si, 'env': env }) return ret
Example #12
Source File: transports.py From sublime_debugger with MIT License | 6 votes |
def __init__(self, command: List[str], cwd: Optional[str]): # taken from Default/exec.py # Hide the console window on Windows startupinfo = None if os.name == "nt": startupinfo = subprocess.STARTUPINFO() #type: ignore startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW #type: ignore super().__init__(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=False, bufsize=0, startupinfo=startupinfo, cwd = cwd) self.closed = False
Example #13
Source File: server.py From byob with GNU General Public License v3.0 | 6 votes |
def _execute(self, args): # ugly method that should be refactored at some point path, args = [i.strip() for i in args.split('"') if i if not i.isspace()] if args.count('"') == 2 else [i for i in args.partition(' ') if i if not i.isspace()] args = [path] + args.split() if os.path.isfile(path): name = os.path.splitext(os.path.basename(path))[0] try: info = subprocess.STARTUPINFO() info.dwFlags = subprocess.STARTF_USESHOWWINDOW , subprocess.CREATE_NEW_ps_GROUP info.wShowWindow = subprocess.SW_HIDE self.child_procs[name] = subprocess.Popen(args, startupinfo=info) return "Running '{}' in a hidden process".format(path) except Exception as e: try: self.child_procs[name] = subprocess.Popen(args, 0, None, None, subprocess.PIPE, subprocess.PIPE) return "Running '{}' in a new process".format(name) except Exception as e: util.log("{} error: {}".format(self._execute.__name__, str(e))) else: return "File '{}' not found".format(str(path))
Example #14
Source File: _utils.py From imageio-ffmpeg with BSD 2-Clause "Simplified" License | 6 votes |
def _popen_kwargs(prevent_sigint=False): startupinfo = None preexec_fn = None creationflags = 0 if sys.platform.startswith("win"): # Stops executable from flashing on Windows (see #22) startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW if prevent_sigint: # Prevent propagation of sigint (see #4) # https://stackoverflow.com/questions/5045771 if sys.platform.startswith("win"): creationflags = 0x00000200 else: preexec_fn = os.setpgrp # the _pre_exec does not seem to work return { "startupinfo": startupinfo, "creationflags": creationflags, "preexec_fn": preexec_fn, }
Example #15
Source File: server.py From byob with GNU General Public License v3.0 | 6 votes |
def _execute(self, args): # ugly method that should be refactored at some point path, args = [i.strip() for i in args.split('"') if i if not i.isspace()] if args.count('"') == 2 else [i for i in args.partition(' ') if i if not i.isspace()] args = [path] + args.split() if os.path.isfile(path): name = os.path.splitext(os.path.basename(path))[0] try: info = subprocess.STARTUPINFO() info.dwFlags = subprocess.STARTF_USESHOWWINDOW , subprocess.CREATE_NEW_ps_GROUP info.wShowWindow = subprocess.SW_HIDE self.child_procs[name] = subprocess.Popen(args, startupinfo=info) return "Running '{}' in a hidden process".format(path) except Exception as e: try: self.child_procs[name] = subprocess.Popen(args, 0, None, None, subprocess.PIPE, subprocess.PIPE) return "Running '{}' in a new process".format(name) except Exception as e: util.log("{} error: {}".format(self.execute.__name__, str(e))) else: return "File '{}' not found".format(str(path))
Example #16
Source File: Radiumkeylogger.py From Radium with Apache License 2.0 | 6 votes |
def subprocess_args(include_stdout=True): if hasattr(subprocess, 'STARTUPINFO'): si = subprocess.STARTUPINFO() si.dwFlags |= subprocess.STARTF_USESHOWWINDOW env = os.environ else: si = None env = None if include_stdout: ret = {'stdout:': subprocess.PIPE} else: ret = {} ret.update({'stdin': subprocess.PIPE, 'stderr': subprocess.PIPE, 'startupinfo': si, 'env': env }) return ret #Function to get the Process ID
Example #17
Source File: __init__.py From pyspelling with MIT License | 6 votes |
def get_process(cmd): """Get a command process.""" if sys.platform.startswith('win'): startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW process = subprocess.Popen( cmd, startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, shell=False ) else: process = subprocess.Popen( cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE, shell=False ) return process
Example #18
Source File: Backend.py From Uranium with GNU Lesser General Public License v3.0 | 6 votes |
def _runEngineProcess(self, command_list) -> Optional[subprocess.Popen]: """Start the (external) backend process.""" kwargs = {} #type: Dict[str, Any] if sys.platform == "win32": su = subprocess.STARTUPINFO() su.dwFlags |= subprocess.STARTF_USESHOWWINDOW su.wShowWindow = subprocess.SW_HIDE kwargs["startupinfo"] = su kwargs["creationflags"] = 0x00004000 # BELOW_NORMAL_PRIORITY_CLASS try: # STDIN needs to be None because we provide no input, but communicate via a local socket instead. The NUL device sometimes doesn't exist on some computers. # STDOUT and STDERR need to be pipes because we'd like to log the output on those channels into the application log. return subprocess.Popen(command_list, stdin = None, stdout = subprocess.PIPE, stderr = subprocess.PIPE, **kwargs) except PermissionError: Logger.log("e", "Couldn't start back-end: No permission to execute process.") except FileNotFoundError: Logger.logException("e", "Unable to find backend executable: %s", command_list[0]) except BlockingIOError: Logger.log("e", "Couldn't start back-end: Resource is temporarily unavailable") except OSError as e: Logger.log("e", "Couldn't start back-end: Operating system is blocking it (antivirus?): {err}".format(err = str(e))) return None
Example #19
Source File: payloads.py From byob with GNU General Public License v3.0 | 5 votes |
def execute(self, args): """ Run an executable program in a hidden process `Required` :param str path: file path of the target program `Optional` :param str args: arguments for the target program """ path, args = [i.strip() for i in args.split('"') if i if not i.isspace()] if args.count('"') == 2 else [i for i in args.partition(' ') if i if not i.isspace()] args = [path] + args.split() if os.path.isfile(path): name = os.path.splitext(os.path.basename(path))[0] try: info = subprocess.STARTUPINFO() info.dwFlags = subprocess.STARTF_USESHOWWINDOW , subprocess.CREATE_NEW_ps_GROUP info.wShowWindow = subprocess.SW_HIDE self.execute.process_list[name] = subprocess.Popen(args, startupinfo=info) return "Running '{}' in a hidden process".format(path) except Exception as e: try: self.execute.process_list[name] = subprocess.Popen(args, 0, None, None, subprocess.PIPE, subprocess.PIPE) return "Running '{}' in a new process".format(name) except Exception as e: log("{} error: {}".format(self.execute.__name__, str(e))) else: return "File '{}' not found".format(str(path))
Example #20
Source File: server.py From chia-blockchain with Apache License 2.0 | 5 votes |
def launch_plotter(root_path, service_array): # we need to pass on the possibly altered CHIA_ROOT os.environ["CHIA_ROOT"] = str(root_path) service_name = service_array[0] service_executable = executable_for_service(service_name) # Swap service name with name of executable service_array[0] = service_executable startupinfo = None if os.name == "nt": startupinfo = subprocess.STARTUPINFO() # type: ignore startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # type: ignore plotter_path = plotter_log_path(root_path) if plotter_path.parent.exists(): if plotter_path.exists(): plotter_path.unlink() else: mkdir(plotter_path.parent) outfile = open(plotter_path.resolve(), "w") log.info(f"Service array: {service_array}") process = subprocess.Popen( service_array, shell=False, stdout=outfile, startupinfo=startupinfo ) pid_path = pid_path_for_service(root_path, service_name) try: mkdir(pid_path.parent) with open(pid_path, "w") as f: f.write(f"{process.pid}\n") except Exception: pass return process, pid_path
Example #21
Source File: payloads.py From byob with GNU General Public License v3.0 | 5 votes |
def execute(self, args): """ Run an executable program in a hidden process `Required` :param str path: file path of the target program `Optional` :param str args: arguments for the target program """ log(args) path, args = [i.strip() for i in args.split('"') if i if not i.isspace()] if args.count('"') == 2 else [i for i in args.partition(' ') if i if not i.isspace()] args = [path] + args.split() if os.path.isfile(path): name = os.path.splitext(os.path.basename(path))[0] try: # attempt to run hidden process info = subprocess.STARTUPINFO() info.dwFlags = subprocess.STARTF_USESHOWWINDOW , subprocess.CREATE_NEW_ps_GROUP info.wShowWindow = subprocess.SW_HIDE self.execute.process_list[name] = subprocess.Popen(args, startupinfo=info) return "Running '{}' in a hidden process".format(path) except Exception as e: # revert to normal process if hidden process fails try: self.execute.process_list[name] = subprocess.Popen(args, 0, None, None, subprocess.PIPE, subprocess.PIPE) return "Running '{}' in a new process".format(name) except Exception as e: log("{} error: {}".format(self.execute.__name__, str(e))) return "{} error: {}".format(self.execute.__name__, str(e)) else: return "File '{}' not found".format(str(path))
Example #22
Source File: downloaders.py From youtube-dl-gui with The Unlicense | 5 votes |
def _create_process(self, cmd): """Create new subprocess. Args: cmd (list): Python list that contains the command to execute. """ info = preexec = None # Keep a unicode copy of cmd for the log ucmd = cmd if os.name == 'nt': # Hide subprocess window info = subprocess.STARTUPINFO() info.dwFlags |= subprocess.STARTF_USESHOWWINDOW else: # Make subprocess the process group leader # in order to kill the whole process group with os.killpg preexec = os.setsid # Encode command for subprocess # Refer to http://stackoverflow.com/a/9951851/35070 if sys.version_info < (3, 0): cmd = convert_item(cmd, to_unicode=False) try: self._proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=preexec, startupinfo=info) except (ValueError, OSError) as error: self._log('Failed to start process: {}'.format(ucmd)) self._log(convert_item(str(error), to_unicode=True))
Example #23
Source File: util.py From pyxform with BSD 2-Clause "Simplified" License | 5 votes |
def run_popen_with_timeout(command, timeout): """ Run a sub-program in subprocess.Popen, pass it the input_data, kill it if the specified timeout has passed. returns a tuple of resultcode, timeout, stdout, stderr """ kill_check = threading.Event() def _kill_process_after_a_timeout(pid): os.kill(pid, signal.SIGTERM) kill_check.set() # tell the main routine that we had to kill # use SIGKILL if hard to kill... return # Workarounds for pyinstaller # https://github.com/pyinstaller/pyinstaller/wiki/Recipe-subprocess startup_info = None if os.name == "nt": # disable command window when run from pyinstaller startup_info = subprocess.STARTUPINFO() # Less fancy version of bitwise-or-assignment (x |= y) shown in ref url. if startup_info.dwFlags == 1 or subprocess.STARTF_USESHOWWINDOW == 1: startup_info.dwFlags = 1 else: startup_info.dwFlags = 0 p = Popen(command, stdin=PIPE, stdout=PIPE, stderr=PIPE, startupinfo=startup_info) watchdog = threading.Timer(timeout, _kill_process_after_a_timeout, args=(p.pid,)) watchdog.start() (stdout, stderr) = p.communicate() watchdog.cancel() # if it's still waiting to run timeout = kill_check.isSet() kill_check.clear() return p.returncode, timeout, stdout, stderr
Example #24
Source File: runInIndesign.py From RunInIndesign with MIT License | 5 votes |
def kill(self): if not self.killed: self.killed = True if sys.platform == "win32": # terminate would not kill process opened by the shell cmd.exe, it will only kill # cmd.exe leaving the child running startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW subprocess.Popen("taskkill /PID " + str(self.proc.pid), startupinfo=startupinfo) else: self.proc.terminate()
Example #25
Source File: popen_spawn.py From pipenv-sublime with MIT License | 5 votes |
def __init__(self, cmd, timeout=30, maxread=2000, searchwindowsize=None, logfile=None, cwd=None, env=None, encoding=None, codec_errors='strict'): super(PopenSpawn, self).__init__(timeout=timeout, maxread=maxread, searchwindowsize=searchwindowsize, logfile=logfile, encoding=encoding, codec_errors=codec_errors) kwargs = dict(bufsize=0, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, stdout=subprocess.PIPE, cwd=cwd, env=env) if sys.platform == 'win32': startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW kwargs['startupinfo'] = startupinfo kwargs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP if isinstance(cmd, string_types) and sys.platform != 'win32': cmd = shlex.split(cmd, posix=os.name == 'posix') self.proc = subprocess.Popen(cmd, **kwargs) self.pid = self.proc.pid self.closed = False self._buf = self.string_type() self._read_queue = Queue() self._read_thread = threading.Thread(target=self._read_incoming) self._read_thread.setDaemon(True) self._read_thread.start()
Example #26
Source File: recipe-511443.py From code with MIT License | 5 votes |
def _invoke(self, cmdline): if sys.platform[:3] == 'win': closefds = False startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW else: closefds = True startupinfo = None if (os.environ.get('DISPLAY') or sys.platform[:3] == 'win' or sys.platform == 'darwin'): inout = file(os.devnull, 'r+') else: # for TTY programs, we need stdin/out inout = None # if possible, put the child precess in separate process group, # so keyboard interrupts don't affect child precess as well as # Python setsid = getattr(os, 'setsid', None) if not setsid: setsid = getattr(os, 'setpgrp', None) pipe = subprocess.Popen(cmdline, stdin=inout, stdout=inout, stderr=inout, close_fds=closefds, preexec_fn=setsid, startupinfo=startupinfo) # It is assumed that this kind of tools (gnome-open, kfmclient, # exo-open, xdg-open and open for OSX) immediately exit after lauching # the specific application returncode = pipe.wait() if hasattr(self, 'fixreturncode'): returncode = self.fixreturncode(returncode) return not returncode
Example #27
Source File: speaker.py From eduActiv8 with GNU General Public License v3.0 | 5 votes |
def start_server(self): if self.android is None: if self.enabled and self.lang.voice is not None: cmd = ['espeak'] cmd.extend(self.lang.voice) try: # IS_WIN32 = 'win32' in str(sys.platform).lower() #maybe sys.platform is more secure is_win = platform.system() == "Windows" if is_win: startupinfo = subprocess.STARTUPINFO() startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW startupinfo.wShowWindow = subprocess.SW_HIDE kwargs = {} kwargs['startupinfo'] = startupinfo self.process = subprocess.Popen(cmd, shell=False, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo) else: if self.debug: self.process = subprocess.Popen(cmd, shell=False, bufsize=0, stdin=subprocess.PIPE) else: self.process = subprocess.Popen(cmd, shell=False, bufsize=0, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.started = True except: self.enabled = False self.started = False print("eduActiv8: You may like to install eSpeak to get some extra functionality, " + "however this is not required to successfully use the game.") else: self.process = None
Example #28
Source File: exec_command.py From sublime-import-helper with MIT License | 5 votes |
def exec(cmd, input): if os.name == "nt": si = subprocess.STARTUPINFO() si.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW proc = subprocess.Popen( cmd, cwd=PACKAGE_PATH, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=si, ) else: proc = subprocess.Popen( cmd, cwd=PACKAGE_PATH, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) if type(input) == str: input = input.encode() outs, errs = proc.communicate(input=input) err = errs.decode().strip() if bool(err): debug("Exec error", err, True) return (err, outs.decode().strip())
Example #29
Source File: VideoMerger.py From DownloaderForReddit with GNU General Public License v3.0 | 5 votes |
def merge_videos(): """ Iterates the MergeSets in the videos_to_merge list and combines the files at the video path and the audio path to the output path. Also sets the output files "date modified" attribute to the date modified specified in the MergeSet if the user settings dictate to do so. """ if ffmpeg_valid: failed_count = 0 for ms in videos_to_merge.values(): try: output_path = get_output_path(ms.output_path) cmd = 'ffmpeg -i "%s" -i "%s" -c:v copy -c:a aac -strict experimental "%s"' % \ (ms.video_path, ms.audio_path, output_path) si = subprocess.STARTUPINFO() si.dwFlags |= subprocess.STARTF_USESHOWWINDOW handle = subprocess.run(cmd, capture_output=True, startupinfo=si) if Injector.get_settings_manager().set_file_modified_date: SystemUtil.set_file_modify_time(output_path, ms.date_modified) except: failed_count += 1 logger.error('Failed to merge video', extra={'video_path': ms.video_path, 'audio_path': ms.audio_path, 'output_path': ms.output_path}, exc_info=True) logger.info('Video merger complete', extra={'videos_successfully_merged': len(videos_to_merge) - failed_count, 'videos_unsuccessfully_merged': failed_count}) clean_up() else: logger.warning('Ffmpeg is not installed: unable to merge video and audio files', extra={'videos_to_merge': len(videos_to_merge)})
Example #30
Source File: server.py From chia-blockchain with Apache License 2.0 | 5 votes |
def launch_service(root_path, service_command): """ Launch a child process. """ # set up CHIA_ROOT # invoke correct script # save away PID # we need to pass on the possibly altered CHIA_ROOT os.environ["CHIA_ROOT"] = str(root_path) # Innsert proper e service_array = service_command.split() service_name = service_array[0] service_executable = executable_for_service(service_name) service_array[0] = service_executable startupinfo = None if os.name == "nt": startupinfo = subprocess.STARTUPINFO() # type: ignore startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW # type: ignore process = subprocess.Popen(service_array, shell=False, startupinfo=startupinfo) pid_path = pid_path_for_service(root_path, service_command) try: mkdir(pid_path.parent) with open(pid_path, "w") as f: f.write(f"{process.pid}\n") except Exception: pass return process, pid_path