您的位置:首页 > 其它

bat脚本读取配置文件

2017-03-31 16:58 393 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  bat脚本