bat脚本读取配置文件

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_24400639/article/details/68927103
bat 读取配置文件

@echo off
:: echo please input(is not null):user passsword expath date
:: 读取配置文件
where bcp
::正式有bcp放开下面这句话
::if "%errorlevel%"=="1" (exit) else (echo Program exists)


for /f "tokens=1,2 delims==" %%i in (config.properties) do (
if "%%i"=="user" set user=%%j
if "%%i"=="password" set password=%%j
if "%%i"=="expath" set expath=%%j
if "%%i"=="date" set date=%%j
if "%%i"=="ip" set ip=%%j
if "%%i"=="tables" set tables=%%j
if "%%i"=="database" set database=%%j
)
::if "%1"=="" (echo user不能为空) else (set user="%1")
::if "%2"=="" (echo password不能为空) else (set password="%2")
::if "%3"=="" (echo expath不能为空) else (set expath="%3")
::if "%4"=="" (set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%") else (set Ymd="%4")
::if "%5"=="" (echo table不能为空) else (set table="%5")
::rem FOR %%C IN (*.BAT *.TXT *.SYS) DO TYPE %%C
::rem 表示此命令后的字符为解释行(注释)
::rem set "Ymd=%date:~,4%%date:~5,2%%date:~8,2%"
::rem set "user=%1"
::rem set "password=%2"
::rem set "path=%3"
echo user:%user%
echo password:%password%
echo expath:%expath%
echo date:%date%
echo database:%database%
echo ip:%ip%

::rem echo %errorlevel% 程序错会返回1,成功为0

echo %tables%
::for %%i in (%tables%) do bcp "select * from %database%.dbo.%%i;" queryout %expath%\%%i.txt -S %ip% -U %user% -P %password% -c
for %%i in (%tables%) do echo "bcp select * from %database%.dbo.%%i; queryout %expath%\%%i.txt -S %ip% -U %user% -P %password% -c"


pause>nul
展开阅读全文

没有更多推荐了,返回首页