Win32 blocking spawn

Paulo Soares psoares at consiste.pt
Fri May 21 08:40:13 EDT 1999


You will have to go to C to do this, if you don't want to resort to
"start /m /w".
Alternatively you can use win32process.CreateProcess with the options
below.

I recently posted code for SendKeys and other functions. You can modify
the function exec in module simpscrp in the following way to lunch an
hidden application:

static PyObject* exec_app(PyObject* self, PyObject* args)
{
    char* buf;
    long wait = 0;
    int error;

    if (!PyArg_ParseTuple(args, "s|i", &buf, &wait))
        return NULL;
    Py_BEGIN_ALLOW_THREADS
    STARTUPINFO          sui;
    PROCESS_INFORMATION  pi;
    memset(&sui, 0, sizeof(sui));
    sui.cb               = sizeof (STARTUPINFO);
/* This will hide the window */
    sui.dwFlags          = STARTF_USESHOWWINDOW;
    sui.wShowWindow      = SW_HIDE;
/*****************************/
    if (error = CreateProcess (NULL, buf, NULL, NULL,
        FALSE, CREATE_DEFAULT_ERROR_MODE,
        NULL, NULL, &sui, &pi ))
    {
        WaitForInputIdle(pi.hProcess, 30000);
        if (wait)
            WaitForSingleObject(pi.hProcess, INFINITE);
    }
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    Py_END_ALLOW_THREADS
    return PyInt_FromLong((long)(error == 0));
}

Best Regards,
Paulo Soares


> -----Original Message-----
> From:	Paul Prescod [SMTP:paul at prescod.net]
> Sent:	Thursday, May 20, 1999 21:48
> To:	Python List
> Subject:	Win32 blocking spawn
> 
> I need to run a command line app from a Windows program.
> I need the command line app to come up hidden or at least in a
> minimized
> window (so I don't think that I can use os.system).
> I need my program to block until it is done (so I don't think that I
> can
> use ShellExecute or WinExec)
> 
> I've got some gross options that involve polling etc. Anybody know
> anything better? Thanks,
> -- 
>  Paul Prescod  - ISOGEN Consulting Engineer speaking for only himself
>  http://itrc.uwaterloo.ca/~papresco
> 
> "It's only a movie. People should get a life." 
>  - George Lucas (http://www.nypost.com/news/9025.htm)




More information about the Python-list mailing list