Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 – Software Mechanic May 13 '11 at 13:59
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

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


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.