Providing the password to psql from a script - Mailing list pgsql-general

From Willem Herremans
Subject Providing the password to psql from a script
Date
Msg-id 402E48A2.9070309@belgacom.net
Whole thread Raw
Responses Re: Providing the password to psql from a script  (Martijn van Oosterhout <kleptog@svana.org>)
Re: Providing the password to psql from a script  (Richard Huxton <dev@archonet.com>)
List 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



pgsql-general by date:

Previous
From: David Helgason
Date:
Subject: nonblocking libpq large object access?
Next
From: Christopher Browne
Date:
Subject: Re: Quad Xeon vs. Dual Itanium