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批处理 & 脚本技术(批处理室) » [Repost] Asking 3 batch processing questions View 2,147 Replies 7
Original Poster Posted 2005-04-14 00:00 ·  中国 湖北 武汉 电信
初级用户
ProGamer
Credits 129
Posts 23
Joined 2005-04-14 00:00
21-year member
UID 38147
Gender Male
Status Offline
I am a new user who comes here out of admiration. I have encountered several problems and would like to ask for advice. I am used to writing common task modules with batch processing in the use of Windows (although it is not a real DOS in XP).
1. May I ask how to reference the system environment variables in the.bat file, that is, the values obtained by the set command. I have tried using for /F %%f in ('set' do... but it seems not easy to obtain the values of specific variables, and can only use for /F %%f in ('set' do echo %%f to enumerate all. Suppose I now only want to reference the value of the %windir% variable, I don't know how to write it.
2. May I ask how to do four arithmetic operations in batch processing? For example, if I echo 1+3, the output is "1+3". If I want to get the sum of 1 plus 3, which is 4, how should I do it?
3. May I ask how to set the local IP and gateway, etc. in the command line? Thank you! Salute!
I'm a progamer who work with windos
not a programmer with windows
Floor 2 Posted 2005-04-14 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
1, In batch processing, referencing the environment variable is just %%windir%%.
2, set /a a=1+3
echo %a%

3, I remember there is a command to change the IP in XP, but I can't remember it for a moment. You can go check it.
http://www.msfans.net/bbs/
Floor 3 Posted 2005-04-14 00:00 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re chenhui530: Your use of %%windir%% confuses me. Why not just use %windir%? As far as I know, this is only used when outputting to a batch file.
Re foxandmonkey: netsh can change local IP, gateway, DNS and other network settings. A simple example:
netsh interface ip set address "Local Area Connection" static 10.0.0.5 255.255.255.0 10.0.0.4 1
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 4 Posted 2005-04-14 00:00 ·  中国 湖南 长沙 电信
高级用户
★★
Credits 772
Posts 273
Joined 2004-10-23 00:00
21-year member
UID 32861
Gender Male
Status Offline
看原文是中文,需要翻译为英文:

Looking at the original poster's meaning, I thought he was going to reference the %windir% variable. Maybe I misunderstood, heh heh~ It's just netsh, I have a bad memory, I just used it the day before yesterday.
http://www.msfans.net/bbs/
Floor 5 Posted 2005-04-14 00:00 ·  中国 湖北 武汉 硚口区 电信
初级用户
ProGamer
Credits 129
Posts 23
Joined 2005-04-14 00:00
21-year member
UID 38147
Gender Male
Status Offline
It works! Thanks again to everyone above (this problem has been hanging on pconline.com.cn for two days without a reply)
I'm a progamer who work with windos
not a programmer with windows
Floor 6 Posted 2005-04-14 00:00 ·  中国 湖北 武汉 电信
初级用户
ProGamer
Credits 129
Posts 23
Joined 2005-04-14 00:00
21-year member
UID 38147
Gender Male
Status Offline
PS. Always wanted to find a list of commonly used command return codes ERRORLEVEL. I don't know which teacher can provide it. Thanks
I'm a progamer who work with windos
not a programmer with windows
Floor 7 Posted 2005-04-14 00:00 ·  中国 山西 太原 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re foxandmonkey:
You can click the following link:
http://bbs.cn-dos.net/dispbbs.asp?BoardID=9&ID=13456
In addition, you can refer to the following foreign website for supplementation:
http://www.computerhope.com/xdoseror.htm (system error codes, which do not return errorlevel)
Finally, these links are only for the return codes of various external commands under DOS 6-7. For the error return codes of commands that update the system, such as reg, fc, etc. under XP, you can view the system help.
In addition, it is suggested that new questions be posted as new topics, so that more people can see this question, study and solve this problem; and also let them see this answer, share and discuss this answer.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2005-04-14 00:00 ·  中国 湖北 武汉 电信
初级用户
ProGamer
Credits 129
Posts 23
Joined 2005-04-14 00:00
21-year member
UID 38147
Gender Male
Status Offline
I'm a progamer who work with windos
not a programmer with windows
Forum Jump: