Providing the password to psql from a script

From: Willem Herremans <willem(dot)herremans(at)belgacom(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Providing the password to psql from a script
Date: 2004-02-14 16:11:14
Message-ID: 402E48A2.9070309@belgacom.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I am developing a client application for postgreSQL in Tcl/Tk (see
http://gborg.postgresql.org/project/pfm ).

It mainly uses PgTcl or pgintcl. I don't have any problems with those,
but I am also trying to call psql from my application for SQL statements
typed directly by the user.

I have used the Tcl command

set psqlChannel [open "|psql $dbname" RDWR]

to create a channel that effectively becomes the input/output channel
for psql. By writing to that channel, SQL statements are sent to psql,
by reading from that channel, the results are received from psql.

That works fine, as long as psql does not prompt for a password. The
problem is that psql does not use this channel for prompting for or
reading the password. Instead, the password is prompted for on, and read
from, the terminal from which the tcl application was started and that
is not what I want, because the Tcl application has already received the
password from the user. It is, as if psql does not use stdout and stdin
for the password.

It would already be helpful if I knew how to make a shell script that
first reads the password and then provides that password to psql, such
that the user is not prompted for the password again.

I have already tried bash constructions like

PASSWORD='blabla'
psql $dbname <<EOF
$PASSWORD
EOF

But the result is still that psql prompts for the password on the
terminal from which the script is run.

Does anybody know how to solve this problem?

Thanks in advance,
--

Willem Herremans

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Helgason 2004-02-14 18:13:28 nonblocking libpq large object access?
Previous Message Lincoln Yeoh 2004-02-14 15:58:37 Re: Quad Xeon vs. Dual Itanium