|
||||||
| Python Discussion forum for Python, a high-level language with simple syntax, but yet powerful. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using python in C | BlueDream | C and C++ | 2 | 05-04-2008 09:02 AM |
| Python for developing software | Kasper | Python | 6 | 03-17-2008 11:45 AM |
| How to learn Python. | Sir_Rimo | Python | 11 | 12-06-2007 05:19 PM |
| Splitting Strings with Empty Separator (Python) | Matt | Python | 3 | 05-18-2007 12:27 PM |
| Python Collection | reachpradeep | Python | 1 | 03-03-2007 02:50 PM |