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-14 18:09
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Can two commands be chained together in FOR under 98? Online now! View 1,182 Replies 12
Original Poster Posted 2004-01-20 00:00 ·  中国 广东 广州 天河区 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
The following can only be executed separately:
for %%1 in (c d e f) do command1 %%1
for %%1 in (c d e f) do command2 %%1

Can the above two commands be executed together? Under 98
Floor 2 Posted 2004-01-21 00:00 ·  中国 香港
管理员
★★★★
專業島民
Credits 4,869
Posts 1,633
Joined 2002-12-10 00:00
23-year member
UID 465
Gender Male
Status Offline
Try this
for %%a in (command1 command2) do for %%b in (c d e f) do %%a %%b
我的網站:http://mw16.2ya.com/ 我的網誌: http://scrappedblog.blogspot.com/
~
我的Winamp正在播放的歌曲:
Floor 3 Posted 2004-01-21 00:00 ·  中国 广东 广州 花都区 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
Hehe! OK, I'll try it. Do I need to add /f,
it's 98 oh




Floor 4 Posted 2004-01-26 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 roy:

Standalone DOS and the DOS mode of 98 both do not support nested loops. You can use the following instead:

for %%a in (command1 command2) do %comspec% /c for %%b in (c d e f) do %%a %%b


※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 5 Posted 2004-02-02 00:00 ·  中国 江苏 扬州 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
Many thanks to both of you, moderator ROY, especially WILLSORT!
The moderator reminded me that a command set can be used inside parentheses, and WILLSORT cleared up my confusion and made me understand COMMAND /C in DOS.
Thanks!
Floor 6 Posted 2004-02-03 00:00 ·  中国 重庆 电信
银牌会员
★★★
Credits 2,202
Posts 499
Joined 2003-06-12 00:00
23-year member
UID 4876
Gender Male
Status Offline
The following is quoted from willsort's post on 2004-1-26 21:29:28:
Re roy:

    Standalone DOS and the DOS mode of 98 both do not support nested loops. You can use the following instead:

    for %%a in (command1 command2) do %comspec% /c for %%b in (c d e f) do %%a %%b





A quick question: is this %comspec% the variable for DOS's command.com?
一年四季,枫叶红了又红;人生四季,失去的,还能再来吗?—— !
Floor 7 Posted 2004-02-03 00:00 ·  中国 江苏 扬州 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
Of course it is! Using the variable can absolutely guarantee no errors
Floor 8 Posted 2004-02-03 00:00 ·  中国 重庆 电信
银牌会员
★★★
Credits 2,202
Posts 499
Joined 2003-06-12 00:00
23-year member
UID 4876
Gender Male
Status Offline
Oh, right right right, of course it is. I forgot about the set comspec=... used in some cases; I don't quite understand what you mean here by guaranteeing no errors. Could you roughly explain what errors and differences might arise from using the variable versus using it directly? Thanks






一年四季,枫叶红了又红;人生四季,失去的,还能再来吗?—— !
Floor 9 Posted 2004-02-03 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 xiaojun:

%comspec% is assigned automatically by the system; you can just refer to it directly, no need to use set.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 10 Posted 2004-06-13 00:00 ·  中国 广东 广州 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
Brother willsort, hello!
At the DOS7.10 command line, the current directory is C:, and C: has three TXT files: 1.txt,2.txt,3.txt. D: also has three TXT files, 4.txt,5.txt,6.txt. I want to compare them. I type:
for %1 in (*.txt) do command /c for %2 in (d:\*.txt) do fc %1 %2>>abc
Then the problem appears: the contents of abc are:
1.txt compared with 4.txt
............(normal)
1.txt compared with 5.txt
Cannot find file 5.txt (the current directory is C:, so at this point it treats d:\5.txt as c:\5.txt, so it can't find it! In other words, in the FOR loop command, from the second time on it ignores d:\ and treats it as being in the current directory!!)
1.txt compared with 6.txt
Likewise it cannot find file 6.txt... and the same below...
That is to say, in the FOR loop, the first round is normal, and the rest all go wrong!
However, I'm doing this at the command line; I haven't tried it in a batch file yet, but it should be the same, right?

Second, when I use %comspec% /c instead of command /c, it says syntax error, strange!!

What's going on?

Also, at the XP command line, this problem does not occur, everything is normal.















Floor 11 Posted 2004-06-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 gotomsdos:

  I cannot reproduce the problem you found. The environment I used was the
Win98 DOS mode with the site's MS-DOS 7.1 installed. I likewise created the above three text files in the roots of drive C and D, and used the following command lines, both of which gave the expected results.

  1. FOR %1 IN (*.TXT) DO COMMAND /C FOR %2 IN (D:\*.TXT) DO FC %1 %2>> E:\ABC.TXT

  2. FOR %1 IN (*.TXT) DO %COMSPEC% /C FOR %2 IN (D:\*.TXT) DO FC %1 %2>> E:\ABC.TXT

  Please check again your runtime environment, as well as the existence and attributes of the text files.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 12 Posted 2004-06-14 00:00 ·  美国
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
willsort: Under the full installation edition of MS-DOS 7.10, it can boot Win3.x, and it can also boot Win95 and Win98, so it shouldn't just be called Win98's. I know that the DOS that comes with Win98 usually cannot boot Win3.x; it isn't that pure.

gotomsdos: Please pay attention to the setting of the LFNFOR command. Try setting LFNFOR to OFF and see whether that so-called "BUG" still appears.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 13 Posted 2004-06-16 00:00 ·  中国 广东 广州 电信
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
23-year member
UID 7105
Gender Male
Status Offline
Thanks to both of you for replying!
willsort: thanks for testing it! The data in all respects are correct.
Wengier: OK, I'll try again according to your suggestion!
Forum Jump: