bat指令碼讀取配置檔案

2021-07-29 20:47:42 字數 1666 閱讀 7409

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

shell指令碼讀取配置檔案

在shell指令碼中讀取配置檔案使用 cat grep,awk和sed 比如在 eaxmple.ini中有 ftp url 127.0.0.1 223 ftp user admin ftp password ftp 則在shell指令碼中讀取配置 ftp url cat eaxmple.ini gr...

讀取配置檔案

類載入器 1 直接用class.forname 類的路徑名 class.forname com.hsf.classloader.classloader 2 用classloder 類載入器 inputstream in classloader.getsystemresourceasstream aa...

Python 讀取MySQL 配置檔案的指令碼

記錄乙個讀取my.cnf配置的指令碼,可以基於該函式做一些mysql 後端運維工作。各位可以基於自己的需求進行修改。指令碼名稱 getcnf.py import sys import os def read cnf cnf path assert cnf path is not none and o...