Running a C ++ program from the Django Framework

I need to run C ++ - a program from the Django Framework. In a way, I get input from the user interface in views.py. When I have these inputs, I need to process the input using my C ++ program and use these results. Is it possible?

+3
source share
4 answers

Compile this program in C ++ and call the module from python using subprocess

+10
source

You can use swig to create a C ++ module that can be imported into python. An alternative is boost :: python (but personnaly, I prefer swig).

+1

- os.popen. , ++ mycpp, - :

results = os.popen('mycpp %s' % user_input).read()

, , os.popen . , , , Python 2.6 .

0

, * nix, ++ - , /home/rishabh/myexe.

django :

import commands

status, res = commands.getstatusoutput("/home/rishabh/myexe")

# status contains process status (0 for success, non-zero for unsuccesful termination) and res contains the output of the process
0

Source: https://habr.com/ru/post/1729019/


All Articles