Skip to content

Instantly share code, notes, and snippets.

@bgnori
Created August 19, 2013 06:16
Show Gist options
  • Save bgnori/6266160 to your computer and use it in GitHub Desktop.
Save bgnori/6266160 to your computer and use it in GitHub Desktop.
mc:
gcc -I/usr/local/include/python3.3m -shared -fPIC -std=c99 -Wall -o mc.so mc.c
#include <Python.h>
static PyObject *
mc_run(PyObject *self, PyObject *args)
{
const char *command;
int sts;
if (!PyArg_ParseTuple(args, "s", &command))
return NULL;
sts = system(command);
return PyLong_FromLong(sts);
}
static PyMethodDef MCMethods[] = {
{"run", mc_run, METH_VARARGS,
"Execute a shell command."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
static struct PyModuleDef mcmodule = {
PyModuleDef_HEAD_INIT,
"mc", /* name of module */
"foobarrrr", /* module documentation, may be NULL */
-1, /* size of per-interpreter state of the module,
or -1 if the module keeps state in global variables. */
MCMethods
};
PyMODINIT_FUNC
PyInit_mc(void)
{
return PyModule_Create(&mcmodule);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment