0

I am developing a software by using wxpython,and I need call a exe file like this way:

core.exe D:\\optionfile

but there is always a black cmd shell flash across explorer in windows. My question is how to call this exe file without show cmd shell. I already tried the following way.

import os
os.system("core.exe D:\\optionfile")
Elivis
  • 287
  • 1
  • 6
  • 17
  • I'm assuming the exe you're calling isn't a compiled version of your program – user2682863 Dec 28 '15 at 03:22
  • You can use the `subprocess` module like this: `subprocess.call(["core.exe", "D:\\optionfile"])`. As shown here: http://stackoverflow.com/questions/89228/calling-an-external-command-in-python – karthikr Dec 28 '15 at 03:22

1 Answers1

0

This is something I've used in the past to accomplish this. Assuming this code in a file and named NoWindowSubProc.py

# use:
# from NoWindowSubProc import subprocess
# subprocess.Popen(... etc...
# subprocess.Popen([exe_path, arg])

def _get_startup_info():
    """Launches 'command' windowless"""
    import subprocess
    startupinfo = subprocess.STARTUPINFO()
    startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
    return startupinfo


_startup_info = _get_startup_info()


class _subprocess_atr(object):
    def __init__(self, atr):
        self.atr = atr

    def __call__(self, *args, **kw):
        return self.atr(*args, startupinfo=_startup_info, **kw)


class subprocess(object):
    def __getattr__(self, atr):
        import subprocess, inspect
        atr = getattr(subprocess, atr)
        if inspect.isroutine(atr):
            return _subprocess_atr(atr) # if the attribute is a method, add windowless startup info
        return atr # not a method, return the normal attribute


subprocess = subprocess()
user2682863
  • 2,680
  • 1
  • 19
  • 34