Answer the question
In order to leave comments, you need to log in
PostgreSQL: how to wait for password input when running script?
Task: ask the user for a password and execute the necessary commands.
Here is my batch file:
@echo on
"C:\Program Files\PostgreSQL\13\bin\psql.exe" -U postgres -f D:/script.sql -a
pause
Answer the question
In order to leave comments, you need to log in
First ask for a password in a variable, and then run it by passing the password from the variable.
@echo off
cls
SET /P psqlpassword="Введите пароль (Enter для завершения): "
if "%psqlpassword%"=="" exit /b
"C:\Program Files\PostgreSQL\13\bin\psql.exe" -U postgres -W %psqlpassword% -f D:/script.sql -a
pause
@echo off
:execute_psql
cls
SET /P psqlpassword="Введите пароль (Enter для завершения): "
if "%psqlpassword%"=="" exit /b
"C:\Program Files\PostgreSQL\13\bin\psql.exe" -U postgres -W %psqlpassword% -f D:/script.sql -a
if errorlevel 1 goto :execute_psql
pause
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question