0

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

3
  • 1
    You 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. Commented Feb 1, 2014 at 6:44
  • 2
    Have 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. Commented Feb 1, 2014 at 8:36
  • I had not, I will look into this instead. Thanks Commented Feb 1, 2014 at 18:42

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Which libraries do you have to include?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.