Board logo

标题: [求助]循环作业 [打印本页]

作者: prodigall     时间: 2007-6-14 10:21    标题: [求助]循环作业

要求:
在DOS下让系统自动重启20次,然后进入到D盘根目录.
请高手赐教
作者: wudixin96     时间: 2007-6-14 10:31
让DOS系统重启??
作者: Climbing     时间: 2007-6-14 10:34
重新启动后还是DOS吗?你自己的逻辑严重错误。

如果重新启动后还是进入同样的DOS,你可以考虑在autoexec.bat中用一个文件来记数。

例如:
...
if exist count.bat call count.bat
if "%count%"=="" set count=0

for %%i in (0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20) do if %count%==%%i goto _%%i

:_0
echo set count=1  > count.bat
reboot

:_1
echo set count=2 > count.bat
reboot

...

:_20
del count.bat
d:

大概是这意思。自己根据情况修改。
作者: prodigall     时间: 2007-6-14 10:53
多谢3楼的
差不多就是这个意思嘛
就是纯DOS系统,进入DOS后重启,进入DOS,再重启......
循环20次。
上述方法应该是可以实现的,但不知是否有更简便的方法呢?
因为特殊需要,其实本是要求做500次开机->复位的动作
按以上的方法可能会很麻烦吧 :)
作者: wudixin96     时间: 2007-6-14 11:13

if not exist 1.txt echo 0 >1.txt
for /f %%i in (1.txt) do set a=%%i
if %a% LSS 50 set /a a+=1 & echo %a%>1.txt & reboot
这样行吗?
作者: Climbing     时间: 2007-6-14 11:55
如果是在cmd环境下当然可以用楼上的方法,但这是在纯DOS,只能另想办法了。

关键的问题是在纯dos下无法用内置的命令实现计数和加减操作。如果使用第三方命令,例如strings,就比较容易了。例如:

在autoexec.bat中这样:

if exist count.bat call count.bat
if "%count%"=="" set count=0
strings count = add 1,%count%
if "%count%"=="500" goto _noreboot
echo set count=%count% > count.bat
reboot

:_noreboot
d:
作者: wudixin96     时间: 2007-6-14 11:58
晕。忘是纯DOS下了。呵呵。
作者: Climbing     时间: 2007-6-14 13:00
strings的下载地址:

http://nufans.net/clone/dostools/string.com