Hi all, I'm tackling my very first python problem so I'm a bit of a newbie to python...
What I've got is a C program that is demonstrating inter process communication - by the use of pipes.
I've got a process that forks, with the child process generating a random number that then pipes the random number to the parent process.
Now what I want to do is use that variable within that process with python to print it to the command line (stdout/screen)
The difficulty I'm having is getting my C variable into the python program.... my code looks like this:
else if ( pid > 0 ) //if this is true this is the parent process
{
// close the file descriptor to set up child for reading
close (fd[1]);
//read the file descriptor and store the variable in pipeResult
read ( fd[0], &pipeResult, sizeof(float) );
//print the variable (just so I can see it piped correctly)
printf ("Read the value of pipe: %f\n", pipeResult);
//Initialise the python environment
Py_Initialize();
//Try to print the C variable in python.... This is not working
PyRun_SimpleString("print pipeResult");
// Close the python environment.
Py_Finalize();
} //end else - parent process
So it looks like I need to figure a way to get my 'C' variable into PyRun_SimpleString( )
Or I have been starting to wonder if it is possible to get the python program to read from one end of the pipe and for my 'C' program to send it down the other end.... This would eliminate the need for me to somehow get my 'C' variable into the python program, obviously introducing other complications such as getting the two different languages to communicate across the processes with a pipe....
Anyone have any ideas?
Thanks
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks