China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 12:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to write such a batch file View 2,405 Replies 9
Original Poster Posted 2005-04-06 00:00 ·  中国 江苏 南京 电信
初级用户
Credits 139
Posts 13
Joined 2005-04-06 00:00
21-year member
UID 37910
Gender Male
Status Offline
The content of auto.bat is: (The purpose is to automatically create a table in the oracle database)
sqlplus system/manager
create table a (a varchar2(10));
exit
But after executing the first sentence, it enters the sqlplus mode, and then the batch processing file can no longer execute downward. How can this problem be solved? Please expert give advice! Thank you!
Floor 2 Posted 2005-04-06 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
Put the last two sentences into a SQL file, and then execute this SQL file with sqlplus. For example:
set tmpsql=%temp%\tmp.sql
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
sqlplus system/manager @%tmpsql%
del %tmpsql%
set tmpsql=
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2005-04-07 00:00 ·  中国 江苏 南京 电信
初级用户
Credits 139
Posts 13
Joined 2005-04-06 00:00
21-year member
UID 37910
Gender Male
Status Offline
Upstairs, thank you for your method, it works, but I still don't quite understand why it's written like this? Can you explain what tmp.sql means? What's it for? What about %temp%
> %tmpsql% echo create table a (a varchar2(10)); > What's the difference between > and >>?
>> %tmpsql% echo exit
Also, if I don't enter system/manager after sqlplus, but when prompted to enter the username, send the username via echo, then press Enter, and when prompted for the password, send the password, can it be done? If it can, how to write it? Thanks, looking forward to it...
Floor 4 Posted 2005-04-08 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
The questions you asked all belong to the basic knowledge of DOS. If I want to explain them clearly to you, it might take several hours. You can go and study the sticky posts of this forum carefully.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 5 Posted 2005-04-12 00:00 ·  中国 江苏 南京 鼓楼区 电信
初级用户
Credits 139
Posts 13
Joined 2005-04-06 00:00
21-year member
UID 37910
Gender Male
Status Offline
Thanks Climbing. I read some materials and learned some knowledge: The output redirection commands > and >>. If > is used, the original file will be deleted and a new file will be recreated, and its content is as described above; if >> is used, the content of the original file will be retained and the new content will be added to the back of the content of the original file. Batch files can also use parameters like functions in the C language (equivalent to command-line parameters of DOS commands), and a parameter identifier "%" is needed. But for set tmpsql=%temp%\tmp.sql
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
I still don't understand very well? I think the meaning of these few sentences should be to write create table a (a varchar2(10)); and exit into the tem.sql file. But what is the relationship between tmpsql in set tmpsql and tmpsql in > %tmpsql%? Is %temp% a parameter? Then where is the value passed to it? Also, the example like "I don't enter system/manager after sqlplus, but when prompted to enter the username, send the username through echo, then press Enter, and when prompted for the password, send the password" seems not to be found. Can you give more guidance? Thanks!
Floor 6 Posted 2005-04-13 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
%temp% is a way to reference an environment variable. For example, if there is an environment variable named temp in the system, the way to use this environment variable is to use %temp% to reference it. Suppose temp = d:\temp, then %temp% means D:\temp. Do you understand this?

After understanding environment variables, then you can understand the role of tmpsql. I created this environment variable to save the temporarily generated SQL file, and the following:
> %tmpsql% echo create table a (a varchar2(10));
>> %tmpsql% echo exit
is to generate this temporary SQL file, and then run it through SQLPlus.

As for what you said about using echo to enter the username and password, it won't work. I can only say: The way of "sqlplus username/password" is the most standard. Of course, you can also use "connect username/password" in the SQL file, but definitely not using echo to enter the username and password, this is just your wishful thinking!
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 7 Posted 2005-04-13 00:00 ·  中国 江苏 南京 电信
初级用户
Credits 139
Posts 13
Joined 2005-04-06 00:00
21-year member
UID 37910
Gender Male
Status Offline
Thanks, Climbing turns out to be this meaning! As for what I said about using echo to input the username and password, the actual purpose is to test whether sqlplus can work normally through a batch file or a single DOS command (and at the same time be able to exit sqlplus and return to the DOS command mode after execution). Because when sqlplus works normally, after entering the correct username and password, it enters the sqlplus working mode and can respond to normal SQL statements, and I can exit sqlplus mode through exit; but if the username or password is incorrect, or sqlplus cannot work normally, it will require entering the username and password 3 times to exit and return to the DOS command mode. At this time, if I enter exit, it will think it is the entered username, and I can only exit after pressing the Enter key several times continuously! I don't know if you understand what I'm talking about? Can it be achieved?
Floor 8 Posted 2005-04-14 00:00 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
I understand what you mean. For the requirements you mentioned, I conducted actual tests and found that when using the sqlplus @xxx.sql method, there is indeed a situation where you need to press Enter three times to exit if the username and password are incorrect. Then I tested several other methods (I am using Oracle 8.1.6), and basically they can meet your requirements. The first method: still use the sqlplus @xxx.sql method, but the content of xxx.sql should be like this, that is, three username and password combinations:
system/manager
system/manager
system/manager
exit The second method: use sqlplus < xxx.txt, and the content of xxx.txt is:
system/manager
exit The third method: type xxx.txt | sqlplus, and the content of xxx.txt is the same as above. The fourth method: using echo is also okay. If the username and password are incorrect, you can exit directly.
echo system/manager | sqlplus
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 9 Posted 2005-04-15 00:00 ·  中国 江苏 南京 电信
初级用户
Credits 139
Posts 13
Joined 2005-04-06 00:00
21-year member
UID 37910
Gender Male
Status Offline
Thanks to enthusiastic Climbing! But there is another problem! When redirecting output, if there are spaces in the environment variables taken, it seems there will be problems? For example: echo hello > %recoverpath%\Log\ListenLog.txt If the value of the environment variable obtained by %recoverpath% has a space, such as: c:\program files\test Then the output file location becomes c:\program, and the content of the file becomes Files\test\Log\ListenLog.txt Is there a way to solve it?
Floor 10 Posted 2005-04-17 00:00 ·  中国 河北 保定 联通
初级用户
Credits 165
Posts 28
Joined 2004-08-09 00:00
21-year member
UID 29892
Gender Male
Status Offline
echo hello > "%recoverpath%\Log\ListenLog.txt"
Forum Jump: