![]() |
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-17 08:48 |
47,813 topics / 349,904 posts / today 1 new / 48,259 members |
| DOS疑难解答 & 问题讨论 (解答室) » Question about recursion in batch files |
| Printable Version 931 / 2 |
| Floor1 smileseeker | Posted 2005-06-03 00:00 |
| 中级用户 Posts 83 Credits 316 | |
|
The system I'm using is win2000
Right now I have 1.bat and 2.bat The contents of 1.bat are: del 1.txt set a=10 set b=1 call 2.bat echo end>>1.txt The contents of 2.bat are: echo %%%a%%%>>1.txt set /a a=a-1 if %a% GTR 0 call 2.bat echo %%%b%%%>>1.txt set /a b=b+1 Execution result: %10% %9% %8% %7% %6% %5% %4% %3% %2% %1% %1% %2% %3% %4% %5% %6% %7% %8% %9% %10% end If I change %%%a%%% in 2.bat to %a%, and %%%b%%% to %b% the result becomes: 10 ECHO is on. ECHO is on. 10 end In the black command window: C:\>del 1.txt C:\>set a=10 C:\>set b=1 C:\>call 2.bat C:\>echo 10 1>>1.txt C:\>set /a a=a-1 C:\>if 9 GTR 0 call 2.bat C:\>echo 9>>1.txt ECHO is on. C:\>set /a a=a-1 C:\>if 8 GTR 0 call 2.bat C:\>echo 8>>1.txt ECHO is on. C:\>set /a a=a-1 C:\>if 7 GTR 0 call 2.bat C:\>echo 7>>1.txt ECHO is on. C:\>set /a a=a-1 C:\>if 6 GTR 0 call 2.bat C:\>echo 6>>1.txt ECHO is on. C:\>set /a a=a-1 C:\>if 5 GTR 0 call 2.bat C:\>echo 5>>1.txt ECHO is on. C:\>set /a a=a-1 C:\>if 4 GTR 0 call 2.bat C:\>echo 4>>1.txt ECHO is on. C:\>set /a a=a-1 C:\>if 3 GTR 0 call 2.bat C:\>echo 3>>1.txt ECHO is on. C:\>set /a a=a-1 C:\>if 2 GTR 0 call 2.bat C:\>echo 2>>1.txt ECHO is on. C:\>set /a a=a-1 C:\>if 1 GTR 0 call 2.bat C:\>echo 1>>1.txt C:\>set /a a=a-1 C:\>if 0 GTR 0 call 2.bat C:\>echo 1>>1.txt C:\>set /a b=b+1 C:\>echo 2>>1.txt ECHO is on. C:\>set /a b=b+1 C:\>echo 3>>1.txt ECHO is on. C:\>set /a b=b+1 C:\>echo 4>>1.txt ECHO is on. C:\>set /a b=b+1 C:\>echo 5>>1.txt ECHO is on. C:\>set /a b=b+1 C:\>echo 6>>1.txt ECHO is on. C:\>set /a b=b+1 C:\>echo 7>>1.txt ECHO is on. C:\>set /a b=b+1 C:\>echo 8>>1.txt ECHO is on. C:\>set /a b=b+1 C:\>echo 9>>1.txt ECHO is on. C:\>set /a b=b+1 C:\>echo 10 1>>1.txt C:\>set /a b=b+1 C:\>echo end 1>>1.txt I don't know where it's wrong Please help, experts |
|
| Floor2 willsort | Posted 2005-06-03 00:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
Re smileseeker:
In the NT-series command line, if you put a number before the redirection symbol, it indicates the handle of the device being redirected, so you just need to add a space after %a% and %b%. By default, command input can be sent from the keyboard (that is, the STDIN handle) to Cmd.exe, and then Cmd.exe sends command output (that is, the STDOUT handle) to the command prompt window. |
|
| Floor3 smileseeker | Posted 2005-06-03 00:00 |
| 中级用户 Posts 83 Credits 316 | |
|
<!>
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |