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-07-01 04:52
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Ask about reading the content of a txt file into a variable under pure DOS View 5,465 Replies 19
Original Poster Posted 2006-08-15 16:21 ·  中国 江苏 苏州 吴中区 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
I've gone through some forum posts and found that FOR in pure DOS is not sufficient in functionality. Some experts mentioned using third-party software or other methods. Could you provide me with a third-party software and a simple usage method? Thanks a lot.

[ Last edited by NaturalJ0 on 2006-8-15 at 16:22 ]
Floor 2 Posted 2006-08-16 16:08 ·  中国 福建 泉州 电信
银牌会员
★★★
Credits 1,276
Posts 469
Joined 2002-12-23 13:00
23-year member
UID 586
Gender Male
From 福建泉州
Status Offline
It is suggested to search the forum first. It seems there are many introductions. You can use programs like LMOD, strings, etc.
QQ:366840202
http://chenall.net
Floor 3 Posted 2006-08-16 23:04 ·  IANA 局域网IP(Private-Use)
初级用户
★★
Credits 177
Posts 52
Joined 2006-06-04 12:00
20-year member
UID 56562
Status Offline
Can you read file content into a variable without using third - party tools?
Floor 4 Posted 2006-08-22 12:13 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
What is the content of your file?
Floor 5 Posted 2006-08-22 18:14 ·  中国 江苏 苏州 电信
中级用户
★★
过度热情
Credits 321
Posts 139
Joined 2006-03-21 17:19
20-year member
UID 52521
Gender Male
Status Offline
It is suggested to make a small tool by yourself with TC. It can be realized with just a dozen of lines of code.
Floor 6 Posted 2006-08-22 22:31 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Originally posted by piziliu2004 at 2006-8-22 18:14:
It is suggested to make a small tool by yourself with TC. It can be realized with just more than a dozen lines of code.

What I did later was exactly like this.
Floor 7 Posted 2006-08-25 12:06 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
Post the content of your txt file. If you want to use something as a variable, give me the batch processing without using third-party software
Floor 8 Posted 2006-08-27 22:37 ·  中国 山东 菏泽 联通
银牌会员
★★★
Credits 1,246
Posts 488
Joined 2003-11-11 00:00
22-year member
UID 12699
Gender Male
Status Offline
Originally posted by NaturalJ0 at 2006-8-22 10:31 PM:

I did it like this later.


Can you post it?
Floor 9 Posted 2006-08-27 22:40 ·  中国 山东 菏泽 联通
银牌会员
★★★
Credits 1,246
Posts 488
Joined 2003-11-11 00:00
22-year member
UID 12699
Gender Male
Status Offline
Originally posted by he200377 at 2006-8-25 12:06 PM:
Post the content of your txt file. What do you want to use as variables, and I'll write a batch script for you, without using third-party software



username
password


Just these two lines, how to write the batch script?


Thanks!
Floor 10 Posted 2006-08-27 23:59 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Originally posted by wang6610 at 2006-8-27 22:37:


Can you post it?

Okay.
I originally wanted a password function, and I wrote one myself with TC, here it is.
http://zhenlove.com.cn/cndos/fileup/files/PASSWORD.rar
Inside is PASSWORD.EXE
When running, it looks for PASSWORD.TXT in the same directory and reads its content as the original password.
When reading, it reads from the beginning of the file to the first carriage return, and there can be spaces and symbols before the carriage return.
Then it asks the user to enter the password to compare with the original password.
If they are the same, a PASSWORD.OK file is generated in the same directory.
If they are different, a PASSWORD.ERR file is generated in the same directory.
Both of these situations are normal operations, and a PASSWORD.RUN file will be generated in both cases. If the user presses Ctrl + C to forcefully interrupt, this file will not be generated.

When using it, you can use echo "Your Password">PASSWORD.TXT in the BAT to set the original password.
Then judge and handle according to the generation of the three status files. When using continuously, you need to delete the status indicator files yourself.

[ Last edited by NaturalJ0 on 2006-8-28 at 00:01 ]
Floor 11 Posted 2006-08-28 07:11 ·  中国 山东 菏泽 联通
银牌会员
★★★
Credits 1,246
Posts 488
Joined 2003-11-11 00:00
22-year member
UID 12699
Gender Male
Status Offline
What is the name of the DOS variable to which PASSWORD.EXE assigns the read string?
Floor 12 Posted 2006-08-28 08:31 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
PASSWORD.EXE is not assigned.
If you need to assign it, just assign it according to the status yourself.
Floor 13 Posted 2006-08-28 12:58 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
namepass.txt
username
password


*.bat
echo set username=%%0 >username.bat
echo set password=%%0 > password.bat
find namepass.txt /i "username" >temp1.bat
find namepass.txt /i "password" >temp2.bat
call temp1.bat
call temp2.bat
del /q username.bat
del /q password.bat
del /q temp1.bat
del /q temp2.bat
echo %username% >>x.txt
echo %password% >>x.txt


I don't know if this expression is correct
If namepass.txt is as follows, then set should be changed to %%1
namepass.txt
username abc
password 123


If namepass.txt is as follows, colons are not allowed in the file name. I think there is a method in a certain post, probably echo !%name:~0,-1%_ !, which is to remove the colon and add a space, so that it can be changed to the same as the above one
namepass.txt
username:abc
password:123
Floor 14 Posted 2006-09-01 15:41 ·  中国 山东 菏泽 联通
银牌会员
★★★
Credits 1,246
Posts 488
Joined 2003-11-11 00:00
22-year member
UID 12699
Gender Male
Status Offline
Originally posted by he200377 at 2006-8-28 12:58 PM:
namepass.txt
username
password


*.bat
echo set username=%%0 >username.bat
echo set password=%%0 > password.bat
find namepass.txt /i "username" >temp1.bat
find namepass. ...



namepass.txt
username:abc
password:123

Thank you!

abc

123

There are two extra spaces after them. How to prevent them from being added? Thank you!

[ Last edited by wang6610 on 2006-9-1 at 15:44 ]
Floor 15 Posted 2006-09-01 16:01 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by wang6610 at 2006-9-1 15:41:

Thanks!

abc

123

There are two extra spaces after them, how to prevent it from adding more? Thanks!

[ Last edited by wang6610 on 2006-9-1 at 15:44 ]

Change echo set username=%%0 >username.bat to echo (set username=%%0)>username.bat or >username.bat echo set username=%%0

[ Last edited by namejm on 2006-11-5 at 12:21 PM ]
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Forum Jump: