Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I got "IOError: [Errno 32] Broken pipe" while writing files in linux.

I am using python to read each line a of csv file and then write into a database table. My code is

f = open(path,'r') 

command = command to connect to database

p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env)

query = " COPY myTable( id, name, address) FROM STDIN WITH  DELIMITER ';' CSV QUOTE   '"'; "

p.stdin.write(query.encode('ascii')) *-->(Here exactly I got the error, p.stdin.write(query.encode('ascii'))
    IOError: [Errno 32] Broken pipe )*

So when I run this program in linux, I got error "IOError: [Errno 32] Broken pipe" . However this works fine when I run in windows7.

Do I need to do some configuration in Linux sever?

Any suggestions will be appreciated. Thank you.

share|improve this question
    
Test without query only or some other string. Also, it would be a better idea to give executable code for ppl to try. Btw, this question belongs better in superuser.com/stackoverflow. –  Anand Jeyahar May 13 '11 at 13:59
1  
How in the world did you come up with this without thinking "There must be an easier way"? –  MikeyB Dec 7 '11 at 23:58

1 Answer 1

Your pipe has broken - the subprocess has already exited. The command you used to connect to the database has finished.


This is probably the WORST POSSIBLE WAY to communicate with the database. Use a native library for the database type in question. I'm not even going to try to enumerate all the reasons why this is bad… just change it. Trust me.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.