mirror of
https://gitlab.com/ita1024/waf.git
synced 2024-11-28 21:10:33 +01:00
51 lines
988 B
C
51 lines
988 B
C
#include <Python.h>
|
|
|
|
static PyObject *
|
|
spam_system(PyObject *self, PyObject *args)
|
|
{
|
|
const char *command;
|
|
int sts;
|
|
|
|
if (!PyArg_ParseTuple(args, "s", &command))
|
|
return NULL;
|
|
sts = system(command);
|
|
return Py_BuildValue("i", sts);
|
|
}
|
|
|
|
static PyMethodDef SpamMethods[] = {
|
|
{"system", spam_system, METH_VARARGS,
|
|
"Execute a shell command."},
|
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
|
};
|
|
|
|
#if PY_VERSION_HEX >= 0x03000000
|
|
|
|
/* Python 3.x code */
|
|
|
|
static struct PyModuleDef spammodule = {
|
|
PyModuleDef_HEAD_INIT,
|
|
"spam", /* name of module */
|
|
"spam_doc", /* module documentation, may be NULL */
|
|
-1, /* size of per-interpreter state of the module,
|
|
or -1 if the module keeps state in global variables. */
|
|
SpamMethods
|
|
};
|
|
|
|
PyMODINIT_FUNC
|
|
PyInit_spam(void)
|
|
{
|
|
(void) PyModule_Create(&spammodule);
|
|
}
|
|
|
|
#else
|
|
|
|
/* Python 2.x code */
|
|
|
|
PyMODINIT_FUNC
|
|
initspam(void)
|
|
{
|
|
(void) Py_InitModule("spam", SpamMethods);
|
|
}
|
|
|
|
#endif
|