Created
August 19, 2013 06:16
-
-
Save bgnori/6266160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mc: | |
gcc -I/usr/local/include/python3.3m -shared -fPIC -std=c99 -Wall -o mc.so mc.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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