Back to index

salome-kernel  6.5.0
Functions | Variables
win32pm.c File Reference
#include <Python.h>
#include <windows.h>

Go to the source code of this file.

Functions

static PyObject * win32pm_spawnhandle (PyObject *self, PyObject *args)
static PyObject * win32pm_spawnpid (PyObject *self, PyObject *args)
static PyObject * win32pm_handle (PyObject *self, PyObject *args)
static PyObject * win32pm_killpid (PyObject *self, PyObject *args)
static PyObject * win32pm_killhandle (PyObject *self, PyObject *args)
PyMODINIT_FUNC initwin32pm (void)

Variables

static PyMethodDef win32pmMethods []

Function Documentation

PyMODINIT_FUNC initwin32pm ( void  )

Definition at line 155 of file win32pm.c.

{
    Py_InitModule("win32pm", win32pmMethods);
}
static PyObject* win32pm_handle ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 103 of file win32pm.c.

{
  int argv1 = 0;
  int argv2 = 0;
  HANDLE ph = 0;
  int pid = 0;
  if (!PyArg_ParseTuple(args, "i|i", &argv1, &argv2))
    return NULL;
  ph = OpenProcess( 1, (BOOL)argv2, argv1  );
  return Py_BuildValue("i", (int)ph );
}
static PyObject* win32pm_killhandle ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 128 of file win32pm.c.

{
  int phId = 0;
  int exitCode = 0;
  BOOL stat = 0;
  if (!PyArg_ParseTuple(args, "i|i", &phId, &exitCode))
    return NULL;

  stat = TerminateProcess( (void*)phId, exitCode );
  return Py_BuildValue("i", (int)stat );
}
static PyObject* win32pm_killpid ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 115 of file win32pm.c.

{
  int pid = 0;
  int exitCode = 0;
  HANDLE ph = 0;
  BOOL stat = 0;
  if (!PyArg_ParseTuple(args, "i|i", &pid, &exitCode))
    return NULL;
  ph = OpenProcess( 1, 0, pid );
  stat = TerminateProcess( ph, exitCode );
  return Py_BuildValue("i", (int)stat );
}
static PyObject* win32pm_spawnhandle ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 23 of file win32pm.c.

{
  char *argv;
  char *flags;
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  DWORD dwProcessFlags = CREATE_NEW_CONSOLE;
  /* Default value as in Python sources:
     CREATE_NEW_CONSOLE has been known to
     cause random failures on win9x.  Specifically a
     dialog:
     "Your program accessed mem currently in use at xxx"
     and a hopeful warning about the stability of your
     system.
     Cost is Ctrl+C wont kill children, but anyone
     who cares can have a go!
  */

  if (!PyArg_ParseTuple(args, "s|s", &argv, &flags))
    return NULL;
  if ( flags && !strcmp( flags, "-nc" ) ) // no console
    dwProcessFlags = 0;

  ZeroMemory( &si, sizeof(si) );
  si.cb = sizeof(si);
  ZeroMemory( &pi, sizeof(pi) );

  if ( !CreateProcess( NULL, argv,
                        NULL,             // Process handle not inheritable. 
                        NULL,             // Thread handle not inheritable. 
                        TRUE,
                        dwProcessFlags,   // Creation flags. 
                        NULL,             // Use parent's environment block. 
                        NULL,             // Use parent's starting directory. 
                        &si,              // Pointer to STARTUPINFO structure.
                        &pi ) )             // Pointer to PROCESS_INFORMATION structure.
     return NULL;
  return Py_BuildValue("i", pi.hProcess);
}
static PyObject* win32pm_spawnpid ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 63 of file win32pm.c.

{
  char* argv;
  char *flags;
  STARTUPINFO si;
  PROCESS_INFORMATION pi;
  DWORD dwProcessFlags = CREATE_NEW_CONSOLE;
  /* Default value as in Python sources:
     CREATE_NEW_CONSOLE has been known to
     cause random failures on win9x.  Specifically a
     dialog:
     "Your program accessed mem currently in use at xxx"
     and a hopeful warning about the stability of your
     system.
     Cost is Ctrl+C wont kill children, but anyone
     who cares can have a go!
  */

  if (!PyArg_ParseTuple(args, "s|s", &argv, &flags))
    return NULL;
  if ( flags && !strcmp( flags, "-nc" ) ) // no console
    dwProcessFlags = 0;

  ZeroMemory( &si, sizeof(si) );
  si.cb = sizeof(si);
  ZeroMemory( &pi, sizeof(pi) );

  if ( !CreateProcess( NULL, argv,
                        NULL,             // Process handle not inheritable. 
                        NULL,             // Thread handle not inheritable. 
                        TRUE,
                        dwProcessFlags,   // Creation flags. 
                        NULL,             // Use parent's environment block. 
                        NULL,             // Use parent's starting directory. 
                        &si,              // Pointer to STARTUPINFO structure.
                        &pi ) )             // Pointer to PROCESS_INFORMATION structure.
     return NULL;
  return Py_BuildValue("i", pi.dwProcessId);
}

Variable Documentation

PyMethodDef win32pmMethods[] [static]
Initial value:
 {
    {"spawnhandle",  win32pm_spawnhandle, METH_VARARGS,
     "Creates new process. Returns windows handle of new process."},
    {"spawnpid",  win32pm_spawnpid, METH_VARARGS,
     "Creates new process. Returns PID of new process."},
    {"handle",  win32pm_handle, METH_VARARGS,
     "Returns windows handle of indicated process PID."},
    {"killpid",  win32pm_killpid, METH_VARARGS,
     "Terminate process by PID."},
    {"killhandle",  win32pm_killhandle, METH_VARARGS,
     "Terminate process by windows process handle."},
    {NULL, NULL, 0, NULL}        
}

Definition at line 140 of file win32pm.c.