2012-02-09 137 views
2

我正在嘗試從命令提示符處讀取登錄cridentials以執行一系列SQL * Loader腳本。
我能夠看到使用set v_設置的變量。但是,我無法訪問這些值。如何訪問Windows批處理作業中的環境變量?

測試文件:

@echo off 

set /P v_user = Username: 
set /P v_pass = Password: 
set /P v_db = Database: 

ECHO Username: "%V_USER%" 
ECHO Password: "%V_PASS%" 
ECHO Database: "%V_DB%" 

set v_ 

pause 

實際結果結果:

Username: 1 <-- Input 
Password: 2 <-- Input 
Database: 3 <-- Input 
Username: "" 
Password: "" 
Database: "" 
v_db =3 
v_pass =2 
v_user =1 

預期結果結果:

Username: 1 <-- Input 
Password: 2 <-- Input 
Database: 3 <-- Input 
Username: "1" 
Password: "2" 
Database: "3" 
v_db =3 
v_pass =2 
v_user =1 

用途:

@echo off 

set /P v_user = Username: 
set /P v_pass = Password: 
set /P v_db = Database: 

sqlldr %v_user%/%v_pass%@%v_db% CONTROL='TABLE_T1.ctl' log='logs/TABLE_T1.log' bad='bad/TABLE_T1.bad' skip=1 
sqlldr %v_user%/%v_pass%@%v_db% CONTROL='TABLE_T2.ctl' log='logs/TABLE_T2.log' bad='bad/TABLE_T2.bad' skip=1 

pause 

回答

5

在組語句刪除=周圍的空間:

echo off 

set /P v_user=Username: 
set /P v_pass=Password: 
set /P v_db=Database: 

ECHO Username: "%V_USER%" 
ECHO Password: "%V_PASS%" 
ECHO Database: "%V_DB%" 

set v_ 

pause 

另一種方法是改變ECHO語句包含相同數量的尾隨空格作爲變量名和=標誌之間使用SET語句:

@echo off 

set /P v_user = Username: 
set /P v_pass = Password: 
set /P v_db = Database: 

ECHO Username: "%V_USER %" 
ECHO Password: "%V_PASS %" 
ECHO Database: "%V_DB %" 

set v_ 

pause 
+0

謝謝,刪除工作的空間。我太習慣於間距不重要的java。 – ScrappyDev 2012-02-09 20:47:23

相關問題