thank you both for a quick response :) i think i understood what you suggest but it is not exactly what i need. To be honest i don't know what is the right technique to do what i need.
I have a program which during it's run sometimes needs to call python in order to preform some tasks. I need a function that calls python and catches pythons stdout
pythonCallBackFunc(const char* pythonInput)
This function is the function to do that.
for example:
pythonCallBackFunc("5**2") needs to print on stdin(or some other file):
PythonResult: 25
pythonCallBackFunc("print 5**2") needs to print on stdin(or some other file):
PythonResult: 25
pythonCallBackFunc("'a'+'b'") needs to print on stdin(or some other file):
PythonResult: 'ab'
pythonCallBackFunc("print 'a'+'b'") needs to print on stdin(or some other file):
PythonResult: ab
pythonCallBackFunc("execfile('temp.py')")
it should print nothing but is needs to run the temp.py script
the next 2 calls need to print the value of result, meaning 4.
pythonCallBackFunc("result = 4")
pythonCallBackFunc("print result")
My problem is to catch all the python output for a given command (pythonInput). First thing I've tried is to redirect python's sdtout and stderr to a file using this script:
#stdout.py
import sys
saveout = sys.stdout
fsock = open('out.log', 'w')
sys.stdout = fsock
#stdout_close.py
sys.stdout = saveout
fsock.close()
#stdout_close.py
fsock = open('error.log', 'w')
sys.stderr = fsock
and after the redirection, I've used the function Py_run_SimpleString
it was ok but this function ignored this types of commands:
Py_run_SimpleString("'a'+'b'")
the output was empty ....
Alex