中国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-08-14 17:14
47,813 topics / 349,901 posts / today 3 new / 48,257 members
DOS学习入门 & 精彩文章 (教学室) » Can two commands be chained together in FOR under 98? Online now!
Printable Version  1,181 / 12
Floor1 GOTOmsdos Posted 2004-01-20 00:00
铂金会员 Posts 1,827 Credits 5,154
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
Floor2 Roy Posted 2004-01-21 00:00
管理员 Posts 1,633 Credits 4,869
Try this
for %%a in (command1 command2) do for %%b in (c d e f) do %%a %%b
Floor3 GOTOmsdos Posted 2004-01-21 00:00
铂金会员 Posts 1,827 Credits 5,154
Hehe! OK, I'll try it. Do I need to add /f,
it's 98 oh




Floor4 willsort Posted 2004-01-26 00:00
元老会员 Posts 1,512 Credits 4,432
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


Floor5 GOTOmsdos Posted 2004-02-02 00:00
铂金会员 Posts 1,827 Credits 5,154
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!
Floor6 xiaojun Posted 2004-02-03 00:00
银牌会员 Posts 499 Credits 2,202
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?
Floor7 GOTOmsdos Posted 2004-02-03 00:00
铂金会员 Posts 1,827 Credits 5,154
Of course it is! Using the variable can absolutely guarantee no errors
Floor8 xiaojun Posted 2004-02-03 00:00
银牌会员 Posts 499 Credits 2,202
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






Floor9 willsort Posted 2004-02-03 00:00
元老会员 Posts 1,512 Credits 4,432
Re xiaojun:

%comspec% is assigned automatically by the system; you can just refer to it directly, no need to use set.
Floor10 GOTOmsdos Posted 2004-06-13 00:00
铂金会员 Posts 1,827 Credits 5,154
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.















Floor11 willsort Posted 2004-06-14 00:00
元老会员 Posts 1,512 Credits 4,432
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.
Floor12 Wengier Posted 2004-06-14 00:00
系统支持 Posts 10,521 Credits 27,736
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.
Floor13 GOTOmsdos Posted 2004-06-16 00:00
铂金会员 Posts 1,827 Credits 5,154
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!
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023