def cmdexec(self, args='', env=None, err=False, expect_crash=False, exe=None): assert self._compiled if sys.platform == 'win32': #Prevent opening a dialog box import ctypes winapi = ctypes.windll.kernel32 SetErrorMode = winapi.SetErrorMode SetErrorMode.argtypes = [ctypes.c_int] SEM_FAILCRITICALERRORS = 1 SEM_NOGPFAULTERRORBOX = 2 SEM_NOOPENFILEERRORBOX = 0x8000 flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX \ | SEM_NOOPENFILEERRORBOX #Since there is no GetErrorMode, do a double Set old_mode = SetErrorMode(flags) SetErrorMode(old_mode | flags) if env is None: envrepr = '' else: envrepr = ' [env=%r]' % (env, ) if exe is None: exe = self.executable_name log.cmdexec('%s %s%s' % (exe, args, envrepr)) res = self.translator.platform.execute(exe, args, env=env) if sys.platform == 'win32': SetErrorMode(old_mode) if res.returncode != 0: if expect_crash: if type(expect_crash ) is int and expect_crash != res.returncode: raise Exception("Returned %d, but expected %d" % (res.returncode, expect_crash)) return res.out, res.err print >> sys.stderr, res.err raise Exception("Returned %d" % (res.returncode, )) if expect_crash: raise Exception("Program did not crash!") if err: return res.out, res.err return res.out
def cmdexec(self, args='', env=None, err=False, expect_crash=False, exe=None): assert self._compiled if sys.platform == 'win32': #Prevent opening a dialog box import ctypes winapi = ctypes.windll.kernel32 SetErrorMode = winapi.SetErrorMode SetErrorMode.argtypes=[ctypes.c_int] SEM_FAILCRITICALERRORS = 1 SEM_NOGPFAULTERRORBOX = 2 SEM_NOOPENFILEERRORBOX = 0x8000 flags = SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX \ | SEM_NOOPENFILEERRORBOX #Since there is no GetErrorMode, do a double Set old_mode = SetErrorMode(flags) SetErrorMode(old_mode | flags) if env is None: envrepr = '' else: envrepr = ' [env=%r]' % (env,) if exe is None: exe = self.executable_name log.cmdexec('%s %s%s' % (exe, args, envrepr)) res = self.translator.platform.execute(exe, args, env=env) if sys.platform == 'win32': SetErrorMode(old_mode) if res.returncode != 0: if expect_crash: return res.out, res.err print >> sys.stderr, res.err raise Exception("Returned %d" % (res.returncode,)) if expect_crash: raise Exception("Program did not crash!") if err: return res.out, res.err return res.out