中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-23 14:09
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » How to write such a batch file
Printable Version  2,616 / 9
Floor1 houen Posted 2005-04-06 00:00
初级用户 Posts 13 Credits 139
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!
Floor2 Climbing Posted 2005-04-06 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
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=
Floor3 houen Posted 2005-04-07 00:00
初级用户 Posts 13 Credits 139
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...
Floor4 Climbing Posted 2005-04-08 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
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.
Floor5 houen Posted 2005-04-12 00:00
初级用户 Posts 13 Credits 139
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!
Floor6 Climbing Posted 2005-04-13 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
%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!
Floor7 houen Posted 2005-04-13 00:00
初级用户 Posts 13 Credits 139
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?
Floor8 Climbing Posted 2005-04-14 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
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
Floor9 houen Posted 2005-04-15 00:00
初级用户 Posts 13 Credits 139
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?
Floor10 小石头 Posted 2005-04-17 00:00
初级用户 Posts 28 Credits 165
echo hello > "%recoverpath%\Log\ListenLog.txt"
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023