I have been looking for this solution for some time and cannot find a solution. Some solutions have suggested using the "system" function in the . However, this suggestion is then always followed by 10 people saying never to use system as it lacks thread safety. Does anyone know how to do this?
Just some info: my python script gets and parses JSON from the internet, then creates a textfile, which the c program then uses. So, instead of having to run one, then the other, I want to run them both in succession from the C exe.
EDIT: Grammer
-
1You may have two separate programs, one for fetching JSON and preparing data for it and another which takes the prepared data and produces some results. You may use, say, a batch file which glues things together. Thus you'll get a simplicity and, well, atomicity, which would allow you to construct a complex and flexible solutions just like Lego constructor does.user3159253– user31592532014年02月01日 06:44:08 +00:00Commented Feb 1, 2014 at 6:44
-
2Have you considered doing it the other way around - i.e. calling into C functions from the Python script? This is the approach normally recommended in the Python community.Karl Knechtel– Karl Knechtel2014年02月01日 08:36:17 +00:00Commented Feb 1, 2014 at 8:36
-
I had not, I will look into this instead. ThanksChrisMcJava– ChrisMcJava2014年02月01日 18:42:39 +00:00Commented Feb 1, 2014 at 18:42
1 Answer 1
You can Use system function in c,c++
like this
system("python ashouri.py");
or
use this code
static PyObject *my_callback = NULL;
static PyObject *
my_set_callback(PyObject *dummy, PyObject *args)
{
PyObject *result = NULL;
PyObject *temp;
if (PyArg_ParseTuple(args, "O:set_callback", &temp)) {
if (!PyCallable_Check(temp)) {
PyErr_SetString(PyExc_TypeError, "parameter must be callable");
return NULL;
}
Py_XINCREF(temp); /* Add a reference to new callback */
Py_XDECREF(my_callback); /* Dispose of previous callback */
my_callback = temp; /* Remember new callback */
/* Boilerplate to return "None" */
Py_INCREF(Py_None);
result = Py_None;
}
return result;
}
Be Successfull