Python subprocess.CREATE_NEW_CONSOLE() Examples

The following are code examples for showing how to use subprocess.CREATE_NEW_CONSOLE(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: Red-GUI   Author: ScarletRav3n   File: Red-GUI.py    (license) View Source Project 7 votes vote down vote up
def run(self):
        interpreter = sys.executable

        if verify_requirements() is None:
            print("You don't have the requirements to start Red. "
                  "Install them from the launcher.")
            if not INTERACTIVE_MODE:
                exit(1)

        if self.autostart is True:
            cmd = (interpreter, "launcher.py", "--start", "--auto-restart")
        else:
            cmd = (interpreter, "launcher.py", "--start")
        try:
            code = subprocess.call(cmd, creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False)
        except KeyboardInterrupt:
            code = 0
        print("Red has been terminated. Exit code: %d" % code) 
Example 2
Project: Red-GUI   Author: ScarletRav3n   File: Red-GUI.py    (license) View Source Project 7 votes vote down vote up
def run(self):
        interpreter = sys.executable

        if interpreter is None:
            print("Python interpreter not found.")
            return

        args = [
            interpreter, "-m",
            "pip", "install",
            "--upgrade", "pip"
        ]

        code = subprocess.call(args, creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False)

        if code == 0:
            print("\nPip has been updated.")
        else:
            print("\nAn error occurred and pip might not have been updated.") 
Example 3
Project: Red-GUI   Author: ScarletRav3n   File: Red-GUI.py    (license) View Source Project 5 votes vote down vote up
def run(self):
        subprocess.Popen(("git", "pull", "--ff-only"),
                         creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False) 
Example 4
Project: Red-GUI   Author: ScarletRav3n   File: Red-GUI.py    (license) View Source Project 5 votes vote down vote up
def run(self):
        remove_reqs_readonly()
        interpreter = sys.executable

        if interpreter is None:
            print("Python interpreter not found.")
            return

        txt = REQS_TXT if self.audio else REQS_NO_AUDIO_TXT

        args = [
            interpreter, "-m",
            "pip", "install",
            "--upgrade",
            "--target", REQS_DIR,
            "-r", txt
        ]

        if IS_MAC:  # --target is a problem on Homebrew. See PR #552
            args.remove("--target")
            args.remove(REQS_DIR)

        code = subprocess.call(args, creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False)

        if code == 0:
            print("Requirements setup completed.")
        else:
            print("An error occurred and the requirements "
                  "setup might not be completed. Consult the docs.") 
Example 5
Project: Red-GUI   Author: ScarletRav3n   File: Red-GUI.py    (license) View Source Project 5 votes vote down vote up
def run(self):
        if self.reqs:
            try:
                shutil.rmtree(REQS_DIR, onerror=remove_readonly)
                print("Installed local packages have been wiped.")
            except FileNotFoundError:
                pass
            except Exception as e:
                print("An error occurred when trying to remove installed "
                      "requirements: {}".format(e))
        if self.data:
            try:
                shutil.rmtree("data", onerror=remove_readonly)
                print("'data' folder has been wiped.")
            except FileNotFoundError:
                pass
            except Exception as e:
                print("An error occurred when trying to remove the 'data' folder: "
                      "{}".format(e))

        if self.cogs:
            try:
                shutil.rmtree("cogs", onerror=remove_readonly)
                print("'cogs' folder has been wiped.")
            except FileNotFoundError:
                pass
            except Exception as e:
                print("An error occurred when trying to remove the 'cogs' folder: "
                      "{}".format(e))

        if self.git_reset:
            code = subprocess.call(("git", "reset", "--hard"),
                                   creationflags=subprocess.CREATE_NEW_CONSOLE, shell=False)
            if code == 0:
                print("Red has been restored to the last local commit.")
            else:
                print("The repair has failed.") 
Example 6
Project: zippy   Author: securesystemslab   File: test_os.py    (license) View Source Project 5 votes vote down vote up
def write_windows_console(self, *args):
        retcode = subprocess.call(args,
            # use a new console to not flood the test output
            creationflags=subprocess.CREATE_NEW_CONSOLE,
            # use a shell to hide the console window (SW_HIDE)
            shell=True)
        self.assertEqual(retcode, 0) 
Example 7
Project: eduActiv8   Author: imiolek-ireneusz   File: speaker.py    (license) View Source Project 5 votes vote down vote up
def start_server(self):
        if self.android is None:
            if self.enabled and self.lang.voice is not None:
                # voices = ["-s 190 -a 100 -p 75 -ven+m1 ", "-s 170 -a 100 -p 80 -ven+m2 ","-s 175 -a 100 -p 80 -ven+m3 ","-s 190 -a 100 -p 60 -ven+f1 ","-s 170 -a 100 -p 75 -ven+f2 ","-s 170 -a 100 -p 80 -ven+m2 "]
                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=True, bufsize=0, close_fds=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, **kwargs)
                        self.process = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                                                        stderr=subprocess.PIPE, startupinfo=startupinfo)
                    else:
                        self.process = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                                                        stderr=subprocess.PIPE)

                    # self.process = subprocess.Popen(cmd, 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.")
                    # stdout and stderr only used to hide the messages from terminal
            else:
                self.process = None 
Example 8
Project: idascripts   Author: ctfhacker   File: _utils.py    (license) View Source Project 5 votes vote down vote up
def subprocess(program, cwd, environment, newlines, joined, shell=True, show=False):
        """Create a subprocess using subprocess.Popen."""
        stderr = subprocess.STDOUT if joined else subprocess.PIPE
        if os.name == 'nt':
            si = subprocess.STARTUPINFO()
            si.dwFlags = subprocess.STARTF_USESHOWWINDOW
            si.wShowWindow = 0 if show else subprocess.SW_HIDE
            cf = subprocess.CREATE_NEW_CONSOLE if show else 0
            return subprocess.Popen(program, universal_newlines=newlines, shell=shell, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, close_fds=False, startupinfo=si, creationflags=cf, cwd=cwd, env=environment)
        return subprocess.Popen(program, universal_newlines=newlines, shell=shell, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=stderr, close_fds=True, cwd=cwd, env=environment) 
Example 9
Project: PCControl   Author: renhongl   File: main.py    (license) View Source Project 5 votes vote down vote up
def __subprocess_call(self, *args, **kwargs):  
        if self.IS_WIN32:  
            startupinfo = subprocess.STARTUPINFO()  
            startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW  
            startupinfo.wShowWindow = subprocess.SW_HIDE  
            kwargs['startupinfo'] = startupinfo  
        retcode = subprocess.call(*args, **kwargs)  
        return retcode 
Example 10
Project: web_ctp   Author: molebot   File: test_os.py    (license) View Source Project 5 votes vote down vote up
def write_windows_console(self, *args):
        retcode = subprocess.call(args,
            # use a new console to not flood the test output
            creationflags=subprocess.CREATE_NEW_CONSOLE,
            # use a shell to hide the console window (SW_HIDE)
            shell=True)
        self.assertEqual(retcode, 0) 
Example 11
Project: django-runner   Author: awecode   File: utils.py    (license) View Source Project 5 votes vote down vote up
def call_command(param, cwd=None):
    if sys.platform == "win32":
        param.insert(0, 'cmd.exe')
        param.insert(1, '/K')
        subprocess.Popen(param, cwd=cwd, creationflags=subprocess.CREATE_NEW_CONSOLE)
    else:
        original_command = ' '.join(param)
        # param.insert(0, 'gnome-terminal')
        # param.insert(1, '-e')
        # print(param)
        cmd = ['gnome-terminal', '-x', 'bash', '-c', '"' + original_command + '; bash"']
        print(' '.join(cmd))
        print(cwd)
        subprocess.Popen(cmd, cwd=cwd, shell=True) 
Example 12
Project: PokeVisionFinder   Author: encode32   File: PokeVisionFinder.py    (license) View Source Project 5 votes vote down vote up
def _pokeSniper(name, lat, lng):
    if _nt and _colors:
        wincolors.paint(wincolors.colors.WARNING)
    try:
        if _terminal:
            subp = subprocess.Popen([ps_path, name, lat, lng], cwd=ps_dir, creationflags = subprocess.CREATE_NEW_CONSOLE)
            subp.wait()
        else:
            subp = subprocess.Popen([ps_path, name, lat, lng], cwd=ps_dir)
            subp.wait()
    except OSError, e:
        error = "[WARNING] - PokeSniper2 Not found on Sniper folder"
        if _nt and _colors:
            wincolors.paint(wincolors.colors.ERROR)
        if _verbose == 0:
            print error
        elif _verbose == 1:
            print '[ERROR] OSError'
            print error
        elif _verbose == 2:
            print '[ERROR] OSError = ' + str(e)
            print error
        _logError(str(e))
        _logError(error)

#Loop 
Example 13
Project: py_daemoniker   Author: Muterra   File: _daemonize_windows.py    (license) View Source Project 5 votes vote down vote up
def _fork_worker(namespace_path, child_env, pid_file, invocation, chdir,
                 stdin_goto, stdout_goto, stderr_goto, _exit_caller, args):
    ''' Opens a fork worker, shielding the parent from cancellation via
    signal sending. Basically, thanks Windows for being a dick about
    signals.
    '''
    # Find out our PID so the daughter can tell us to exit
    my_pid = os.getpid()
    # Pack up all of the args that the child will need to use.
    # Prepend it to *args
    payload = (my_pid, pid_file, chdir, stdin_goto, stdout_goto,
               stderr_goto, _exit_caller) + args
    
    # Pack it up. We're shielded from pickling errors already because pickle is
    # needed to start the worker.
    # Write the payload to the namespace passer using the highest available
    # protocol
    with open(namespace_path, 'wb') as f:
        pickle.dump(payload, f, protocol=-1)
    
    # Invoke the invocation!
    daemon = subprocess.Popen(
        invocation,
        # This is important, because the parent _forkish is telling the child
        # to run as a daemon via env. Also note that we need to calculate this
        # in the root _daemonize1, or else we'll have a polluted environment
        # due to the '__CREATE_DAEMON__' key.
        env = child_env,
        # This is vital; without it, our process will be reaped at parent
        # exit.
        creationflags = subprocess.CREATE_NEW_CONSOLE,
    )
    # Busy wait until either the daemon exits, or it sends a signal to kill us.
    daemon.wait() 
Example 14
Project: ouroboros   Author: pybee   File: test_os.py    (license) View Source Project 5 votes vote down vote up
def write_windows_console(self, *args):
        retcode = subprocess.call(args,
            # use a new console to not flood the test output
            creationflags=subprocess.CREATE_NEW_CONSOLE,
            # use a shell to hide the console window (SW_HIDE)
            shell=True)
        self.assertEqual(retcode, 0) 
Example 15
Project: NLT   Author: nxa-Rawrity   File: NLT.py    (license) View Source Project 5 votes vote down vote up
def RunDFC(self):

        try:
            from subprocess import Popen
            Popen(dfcLoc, creationflags=subprocess.CREATE_NEW_CONSOLE)
            #file.communicate()
        except:
            logging.info('Unable to load Dummy File Creator.  Ensure it can be found in '+ dfcLoc) 
Example 16
Project: maestro   Author: InWorldz   File: RegionHost.py    (license) View Source Project 5 votes vote down vote up
def RunCommandEx(self, cwd, cmd, cmdargs):
        try:
            cmdline = "{0} {1}".format(cmd, cmdargs)    
            p = psutil.Popen(cmdline, close_fds=True, cwd=cwd, creationflags=subprocess.CREATE_NEW_CONSOLE)
            return p
        except Exception: 
            return None 
Example 17
Project: maestro   Author: InWorldz   File: RegionHost.py    (license) View Source Project 5 votes vote down vote up
def RunCommandAsEx(self, username, password, cwd, cmd, cmdargs):
        try:
            cmdline = "PsExec -u {0} -p {1} {2} {3}".format(username, password, cwd, cmd, cmdargs)
            p = psutil.Popen(cmdline, close_fds=True, cwd=cwd, creationflags=subprocess.CREATE_NEW_CONSOLE)
            return p
        except Exception: 
            return None 
Example 18
Project: kbe_server   Author: xiaohaoppy   File: test_os.py    (license) View Source Project 5 votes vote down vote up
def write_windows_console(self, *args):
        retcode = subprocess.call(args,
            # use a new console to not flood the test output
            creationflags=subprocess.CREATE_NEW_CONSOLE,
            # use a shell to hide the console window (SW_HIDE)
            shell=True)
        self.assertEqual(retcode, 0) 
Example 19
Project: server   Author: happypandax   File: gui.py    (license) View Source Project 5 votes vote down vote up
def convert(self):
        if self.args:
            p = Popen([sys.executable, os.path.abspath(HPtoHPX.__file__), *self.args], creationflags=CREATE_NEW_CONSOLE)
            Thread(target=self._parent.watch_process, args=(None, p)).start()
            self.close() 
Example 20
Project: server   Author: happypandax   File: gui.py    (license) View Source Project 5 votes vote down vote up
def start_server(self):
        p = Popen([sys.executable, os.path.abspath(main.__file__)], creationflags=CREATE_NEW_CONSOLE)
        Thread(target=self.watch_process, args=(self.toggle_server, p)).start()
        return p 
Example 21
Project: OSPTF   Author: xSploited   File: interactive_shell.py    (license) View Source Project 4 votes vote down vote up
def interactive_open(program=None, encoding=None):
    try:
        if program is None:
            if sys.platform=="win32":
                program="cmd.exe"
            else:
                if "SHELL" in os.environ:
                    program=os.environ["SHELL"]
                else:
                    program="/bin/sh"
                encoding=None

        fullargs=[program]
        if sys.platform=="win32":
            try:
                #couldn't find a better way, none of the following methods worked for me : kernel32.SetConsoleOutputCP(), locale.getpreferredencoding(), sys.stdout.encoding
                encoding="cp"+str(re.findall(r".*:\s*([0-9]+)",subprocess.check_output("chcp", shell=True))[0])
            except:
                pass
            if program.endswith("powershell") or program.endswith("powershell.exe"):
                fullargs=["powershell.exe", "-C", "-"] # trick to make powershell work without blocking
        if encoding is None:
            encoding=locale.getpreferredencoding()
        print "Opening interactive %s (with encoding %s)..."%(program,encoding)
        if sys.platform=="win32":
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = subprocess.SW_HIDE
            p = Popen(fullargs, stdout=PIPE, stderr=PIPE, stdin=PIPE, bufsize=0, close_fds=ON_POSIX, universal_newlines=True, startupinfo=startupinfo)
        else:
            p = Popen(fullargs, stdout=PIPE, stderr=PIPE, stdin=PIPE, bufsize=0, close_fds=ON_POSIX, universal_newlines=True)
        q = Queue()
        q2 = Queue()
        t = Thread(target=write_output, args=(p.stdout, q))
        t.daemon = True
        t.start()

        t = Thread(target=write_output, args=(p.stderr, q2))
        t.daemon = True
        t.start()

        t = Thread(target=flush_loop, args=(q, encoding))
        t.daemon = True
        t.start()

        t = Thread(target=flush_loop, args=(q2, encoding))
        t.daemon = True
        t.start()

        while True:
            line = raw_input()
            p.stdin.write(line+"\n")
            p.stdin.flush()
            if line.strip()=="exit":
                break
    except Exception as e:
        print(traceback.format_exc()) 
Example 22
Project: pupy   Author: ru-faraon   File: interactive_shell.py    (license) View Source Project 4 votes vote down vote up
def interactive_open(program=None, encoding=None):
    try:
        if program is None:
            if sys.platform=="win32":
                program="cmd.exe"
            else:
                if "SHELL" in os.environ:
                    program=os.environ["SHELL"]
                else:
                    program="/bin/sh"
                encoding=None

        fullargs=[program]
        if sys.platform=="win32":
            try:
                #couldn't find a better way, none of the following methods worked for me : kernel32.SetConsoleOutputCP(), locale.getpreferredencoding(), sys.stdout.encoding
                encoding="cp"+str(re.findall(r".*:\s*([0-9]+)",subprocess.check_output("chcp", shell=True))[0])
            except:
                pass
            if program.endswith("powershell") or program.endswith("powershell.exe"):
                fullargs=["powershell.exe", "-C", "-"] # trick to make powershell work without blocking
        if encoding is None:
            encoding=locale.getpreferredencoding()
        print "Opening interactive %s (with encoding %s)..."%(program,encoding)
        if sys.platform=="win32":
            startupinfo = subprocess.STARTUPINFO()
            startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW
            startupinfo.wShowWindow = subprocess.SW_HIDE
            p = Popen(fullargs, stdout=PIPE, stderr=PIPE, stdin=PIPE, bufsize=0, close_fds=ON_POSIX, universal_newlines=True, startupinfo=startupinfo)
        else:
            p = Popen(fullargs, stdout=PIPE, stderr=PIPE, stdin=PIPE, bufsize=0, close_fds=ON_POSIX, universal_newlines=True)
        q = Queue()
        q2 = Queue()
        t = Thread(target=write_output, args=(p.stdout, q))
        t.daemon = True
        t.start()

        t = Thread(target=write_output, args=(p.stderr, q2))
        t.daemon = True
        t.start()

        t = Thread(target=flush_loop, args=(q, encoding))
        t.daemon = True
        t.start()

        t = Thread(target=flush_loop, args=(q2, encoding))
        t.daemon = True
        t.start()

        while True:
            line = raw_input()
            p.stdin.write(line+"\n")
            p.stdin.flush()
            if line.strip()=="exit":
                break
    except Exception as e:
        print(traceback.format_exc())