Linux – IOError: [Errno 32] Broken pipe

linuxpython

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.

Best Answer

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.