Exemplo n.º 1
0
    def _startBabelfish(self):
        outfile = _NULFILE
        sa = pywintypes.SECURITY_ATTRIBUTES()
        sa.bInheritHandle = 1
        try:
            outh = win32file.CreateFile(outfile,
                    win32file.GENERIC_WRITE, 0, sa, win32file.CREATE_ALWAYS,
                    win32file.FILE_ATTRIBUTE_NORMAL, None)
        except pywintypes.error:
            self._error("error creating " + outfile)
            raise

        try:
            inh = win32file.CreateFile(self.script,
                    win32file.GENERIC_READ, 0, sa, win32file.OPEN_EXISTING,
                    win32file.FILE_ATTRIBUTE_NORMAL, None)
        except pywintypes.error:
            self._error("error opening " + self.script)
            win32api.CloseHandle(outh)
            raise

        argv = [self.applicationName, '--vanilla', '--slave']
        commandLine = msc_argv2str(argv)
        processSecurityAttributes = None
        threadSecurityAttributes = None
        fInheritHandles = 1
        creationFlags = win32process.CREATE_NO_WINDOW
        environment = None
        currentDirectory = None
        startupInfo = win32process.STARTUPINFO()
        startupInfo.dwFlags = win32process.STARTF_USESTDHANDLES
        startupInfo.hStdInput = inh
        startupInfo.hStdOutput = outh
        startupInfo.hStdError = outh

        try:
            procHandle, threadHandle, procId, threadId = win32process.CreateProcess(
                    self.applicationName, commandLine,
                    processSecurityAttributes, threadSecurityAttributes,
                    fInheritHandles, creationFlags,
                    environment, currentDirectory,
                    startupInfo)

            win32api.CloseHandle(threadHandle)
        except pywintypes.error:
            self._error("error executing " + self.applicationName)
            win32api.CloseHandle(outh)
            win32api.CloseHandle(inh)
            raise

        win32api.CloseHandle(outh)
        win32api.CloseHandle(inh)

        return procHandle
Exemplo n.º 2
0
def main(argv):
    try:
        from signal import signal, SIGHUP, SIGINT, SIG_IGN

        signal(SIGHUP, SIG_IGN)
        signal(SIGINT, SIG_IGN)
    except ImportError:
        # presumably we're on Windows: nothing to do
        pass

    try:
        # this should work on posix systems and Windows with Python >= 2.6
        subprocess.Popen(argv, close_fds=True)
    except ValueError:
        try:
            # Python versions before 2.6 don't allow close_fds=True on Windows
            import pywintypes
            import win32process

            try:
                from nws.util import msc_argv2str, which
            except ImportError:
                # nws-python isn't installed, but we just need nwsutil.py
                from nwsutil import msc_argv2str, which

            if not os.path.isabs(argv[0]):
                argv[0] = which(argv[0])[0]

            commandLine = msc_argv2str(argv)
            processSecurityAttributes = None
            threadSecurityAttributes = None
            fInheritHandles = 0
            creationFlags = win32process.CREATE_NO_WINDOW
            environment = None
            currentDirectory = None
            startupInfo = win32process.STARTUPINFO()

            procHandle, threadHandle, procId, threadId = win32process.CreateProcess(
                argv[0],
                commandLine,
                processSecurityAttributes,
                threadSecurityAttributes,
                fInheritHandles,
                creationFlags,
                environment,
                currentDirectory,
                startupInfo,
            )
        except ImportError:
            # presumably we're on Windows using Python < 2.6
            # we'll inherit handles, but this is better than nothing
            subprocess.Popen(argv)
Exemplo n.º 3
0
 def _buildCmd(self):
     return msc_argv2str([self.applicationName, '-u'])