How to move out variables declaration from a bat file to another bat file?
-
26-10-2019 - |
문제
I need to create 2 .bat files:
- To dump my PostgreSQL database
- To restore the PostgreSQL database
How can I move out variables (database name, login, passw, etc...) to an external file so both .bat files can use the same external file with variable declarations.
Thanks!
해결책
File #1, e.g. setup_env.cmd
set server=localhost
set db=postgres
set port=5432
File #2, e.g. do_dump.cmd
call ~dp0setup_env.cmd
pg_dump -h %server% -p %port% %db%
다른 팁
with defaults:
set server=localhost
set db=yourdb
set port=5432
if {%1}=={} goto dostuff
set server=%1
if {%2}=={} goto dostuff
set db=%2
if {%3}=={} goto dostuff
set port=%3
:dostuff
ECHO
<your command> %server% %db% %port%
You can call it from different file:
call dump.bat <servername> <dbname> <portnumber>
제휴하지 않습니다 StackOverflow