exception handling; python program that interacts with postgresql db

damacy wegein at gmail.com
Wed Aug 2 21:15:57 EDT 2006


hi, there. i have this question which might sound quite stupid to some
people, but here we go anyway.

i have written a python program which interacts with a postgresql
database. what it does is simply drops an existing database called
'mytempdb'.

the code looks like below;

link = subprocess.Popen(command, stdin = subprocess.PIPE, stdout =
subprocess.PIPE, shell = True)
link.communicate(password)
link.wait()

where command looks like "psql -h 127.0.0.1 -U postgres -W -f filename"
and
filename is the name of the file which contains a single SQL command
which is "drop database mytempdb".

the program works fine as long as a correct password is supplied,
however, i have a problem if the password is incorrect since this
exception is *not* handled within the scope of my program, instead,
what is does is showing some error messages in the prompt. so my
program, without knowing whether an errors has taken place or not, goes
on to execute the next task.

any clue? please let me know if you think the problem is not well
addressed. =)

thanks. have a nice one.




More information about the Python-list mailing list