piping from C to python in UNIX


 
Thread Tools Search this Thread
Top Forums Programming piping from C to python in UNIX
# 1  
Old 05-04-2008
piping from C to python in UNIX

Hi,

I'm trying to wrap my head around piping in C - I've got a small C program that forks and pipes stuff from the child process to the parent process.

Currently the child process calls a C program that squirts out random numbers which then pipes the result to the parent process.

The parent process reads the pipe and simply prints the random number.

What I would like to do is then use this piped integer in a python program.

So firstly I think I have to include the python library within the C program.

#include <python2.4/Python.h>

then call python with:

Py_Initialize();

But when I call this the gcc compiler gives me the error:
undefined reference to 'Py_Initialize'

So I'm guessing that the header file I'm using is incorrect..?

the python version I'm using is:

Python 2.4.3 (#1, Jun 13 2006, 16:41:18)

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Applying python on all the files in one folder --UNIX

Dear all, I know this might be a simple and silly question but I am struggling with it I have a long unix script and in a section of if I want to use a python script which should select all the files and run the script on it (as a whole) the loop I have is selecting file by file and I dont know... (2 Replies)
Discussion started by: A-V
2 Replies

2. Homework & Coursework Questions

Unix Piping Problem

Hey guys. I'm very new to Unix. I'm pretty fluent in Java and C, but I have never actually used Unix for anything. I am in an Operating Systems course now and I have an assignment to write a piece of code that involves forks and piping. I'm stuck. 1. The problem statement, all variables and... (6 Replies)
Discussion started by: itsjimmy91
6 Replies

3. Shell Programming and Scripting

Piping to a python script

Hello, I have a python script (not created by me), let's call it myscript, which I call with several parameters. If I don't provide the --password parameter, the script will ask the user to input the password. So I run the script like this: /wherever/myscript --username=whoever... (3 Replies)
Discussion started by: gplayersv
3 Replies

4. Shell Programming and Scripting

Exit code from piping in unix shell script

Hi , I have following code in my shell script : "$TS_BIN/tranfrmr" "${TS_SETTINGS}/tranfrmr_p1.stx" "${TS_LOGS}/tranfrmr_p1.err" | ( "$TS_BIN/cusparse" "${TS_SETTINGS}/cusparse_p2.stx" "${TS_LOGS}/cusparse_p2.err" | ( "$TS_BIN/tsqsort" "${TS_SETTINGS}/srtforpm_p3.stx"... (8 Replies)
Discussion started by: sonu_pal
8 Replies

5. Shell Programming and Scripting

Piping Unix Variable Array values into AWK

#ksh Here is my code: ERRORLIST="43032 12001 12002 12003 12004 34019 49015 49016 49017 49018 49024 49025 49026 58004 72003 12005 12006 12007 12008 12011 12012 16024 16023" for ERROR in ${ERRORLIST} do awk -v l="$lastdate" '/^....-..-../&&$0>l{d=$0}d&&/Error: '"${ERROR}"'/{print... (3 Replies)
Discussion started by: k1ko
3 Replies

6. Shell Programming and Scripting

Need your help for the spell checker in unix or python

Hi, Want to know is there any command to correct the spelling using unix or python? Unix command "spell" will give only the list of the incorrect words . But i want the output along with the corrected word . Thanks in advance (1 Reply)
Discussion started by: vini
1 Replies

7. Shell Programming and Scripting

Python in UNIX

Hi, I am going to handle a project that uses Python on AIX or SunSolaris Plateform. Please tell me what is Python and how and why we should use Python. Please suggest. Thanx. (2 Replies)
Discussion started by: sanjay1979
2 Replies

8. Programming

Java with Unix (Redirection + Piping)

Hi, To explain this question I will have to go into a bit of detail. I hope you don't mind. currently I have a log handler (an already compiled c++ version) and what it does is makes a log file and writes all the unix output (echo, etc) of a script to that log file. To me the log_handler is... (3 Replies)
Discussion started by: fluke_perf
3 Replies

9. UNIX for Dummies Questions & Answers

Piping in UNIX

All, I am a UNIX novice with a question that I hope you can help me with. I have a UNIX application called "Tole" that formats and displays specific information about customers. I can display the information for up to 30 customers by seperating customer IDs using commas in this format: Tole -c... (3 Replies)
Discussion started by: simo007
3 Replies

10. UNIX for Advanced & Expert Users

Python, HTML, and Unix

Hi Experts, This may be the wrong category for posting my question, or it could be the perfect category to post. I have no idea how difficult my problem is. I have python 2.3 installed in my server machine. I am trying to create a web page with python script in it. Now this can be a .html... (1 Reply)
Discussion started by: davidfrank
1 Replies
Login or Register to Ask a Question
FORK(2) 						      BSD System Calls Manual							   FORK(2)

NAME
fork -- create a new process SYNOPSIS
#include <sys/types.h> #include <unistd.h> pid_t fork(void); DESCRIPTION
Fork() causes creation of a new process. The new process (child process) is an exact copy of the calling process (parent process) except for the following: o The child process has a unique process ID. o The child process has a different parent process ID (i.e., the process ID of the parent process). o The child process has its own copy of the parent's descriptors. These descriptors reference the same underlying objects, so that, for instance, file pointers in file objects are shared between the child and the parent, so that an lseek(2) on a descriptor in the child process can affect a subsequent read or write by the parent. This descriptor copying is also used by the shell to establish standard input and output for newly created processes as well as to set up pipes. o The child processes resource utilizations are set to 0; see setrlimit(2). RETURN VALUES
Upon successful completion, fork() returns a value of 0 to the child process and returns the process ID of the child process to the parent process. Otherwise, a value of -1 is returned to the parent process, no child process is created, and the global variable errno is set to indicate the error. ERRORS
Fork() will fail and no child process will be created if: [EAGAIN] The system-imposed limit on the total number of processes under execution would be exceeded. This limit is configuration- dependent. [EAGAIN] The system-imposed limit MAXUPRC (<sys/param.h>) on the total number of processes under execution by a single user would be exceeded. [ENOMEM] There is insufficient swap space for the new process. SEE ALSO
execve(2), wait(2) HISTORY
A fork() function call appeared in Version 6 AT&T UNIX. 4th Berkeley Distribution June 4, 1993 4th Berkeley Distribution