Ticket #6117: spammodule.c

File spammodule.c, 500 bytes (added by artur_spruce@…, 18 years ago)

Test extension module - C source

Line 
1#include <Python.h>
2
3static PyObject *
4spam_system(PyObject *self, PyObject *args)
5{
6    const char *command;
7    int sts;
8
9    if (!PyArg_ParseTuple(args, "s", &command))
10        return NULL;
11    sts = system(command);
12    return Py_BuildValue("i", sts);
13}
14
15static PyMethodDef SpamMethods[] = {
16    {"system",  spam_system, METH_VARARGS,
17     "Execute a shell command."},
18    {NULL, NULL, 0, NULL}        /* Sentinel */
19};
20
21PyMODINIT_FUNC
22initspam(void)
23{
24    Py_InitModule("spam", SpamMethods);
25}
26