How to use a command line parameter to provide input at a subsequent prompt (batch file)
I am using a batch file to run a specific operation in my application. The command I'm using doesn't take a password as a parameter, but asks for it at runtime. This makes it difficult to automate this script. I would like to know how I can take a password as a parameter and provide the application when it asks.
a source to share
In response to Johannes' answer , you need to change your call to pg_dump
something like this:
echo %3|pg_dump -h %1 -U %2 %4 > %5
The problem is that pg_dump doesn't let you pass the password through stdin. This means that this solution will not work here.
But as you can read in the docs here and here , there is a (unsafe) way to provide a password via an environment variable PGPASSWORD
.
So just change your batch file like this:
... set PGPASSWORD=%3 pg_dump -h %1 -U %2 %4 > %5 ...
a source to share