subprocess to C program

Aaron Brady castironpi at gmail.com
Sun Dec 14 01:37:54 CET 2008


Hi,

I am writing a C process and I want to read data from a file that I
write to in Python.  I'm creating a pipe in Python, passing it to the
C process, and calling '_read'.  It gives me error 9, bad file number.

Python code:

import subprocess as s, os
r, w= os.pipe( )
os.write( w, 'abcdefghij\n' )
a= s.Popen( [ r'C:\Documents and Settings\usr\Desktop\working
\try_start', '%i'%r, '%i'%w ] )

C code:

char buf[ 16 ];
memset( buf, 0, 16 );
int readfd= atoi( argv[ 1 ] );
int ct= _read( readfd, buf, 15 );
printf( "\n\n'_read %i %i %i': %s\n", ct, readfd, errno, buf );

Output:

'_read -1 3 9'

meaning that 'ct' is -1, 'readfd' is 3, and 'errno' is 9.  I want 'ct'
to be 11 at this point.  Thanks in advance.



More information about the Python-list mailing list