如何在 Windows 批处理作业中访问环境变量?
我正在尝试从命令提示符读取登录凭据,以便执行一系列 SQL*Loader 脚本。
我可以看到变量是使用 set v_ 设置的。但是,我无法访问这些值。
测试文件:
@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
I'm trying to read login cridentials from the command prompt in order to execute a series of SQL*Loader Scripts.
I am able to see that the variable got set using set v_. However, I can't access the values.
Test File:
@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
Actual Result Result:
Username: 1 <-- Input
Password: 2 <-- Input
Database: 3 <-- Input
Username: ""
Password: ""
Database: ""
v_db =3
v_pass =2
v_user =1
Expected Result Result:
Username: 1 <-- Input
Password: 2 <-- Input
Database: 3 <-- Input
Username: "1"
Password: "2"
Database: "3"
v_db =3
v_pass =2
v_user =1
Intended Use:
@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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除 set 语句中
=
周围的空格:另一种方法是更改 ECHO 语句,使其包含与变量名和
=< 之间使用的 SET 语句相同数量的尾随空格。 /代码> 标志:
Remove the spaces around the
=
in the set statements:The other alternative is to change the ECHO statements to contain the same number of trailing spaces as the SET statement used between the variable name and
=
sign: