Reputation: 135
If I execute a psql command in a hidden cmd process it will open up a cmd asking for the password (I'm doing this from C# by starting a new CMD.exe process with the respective args). Is there a way to avoid this? Ideally the password won't be stored anywhere, it will simply be passed as an arg.
Upvotes: 1
Views: 373
Reputation: 648
PostgreSQL will automatically look for a an environment variable called PGPASSWORD before it requests one. If the environment variable is set it will continue on without asking for a password.
You can set the environment variable before hand in a batch script and then set it to nothing when done. Like so:
set PGPASSWORD=%1
pgsql.exe your arguments here
set PGPASSWORD=
Assuming you're passing the password as the first argument to the batch script this will set PGPASSWORD to what ever you pass it.
Upvotes: 3