Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 为什么这个批处理脚本不能正常工作?_Loops_Batch File_For Loop_Cmd - Fatal编程技术网

Loops 为什么这个批处理脚本不能正常工作?

Loops 为什么这个批处理脚本不能正常工作?,loops,batch-file,for-loop,cmd,Loops,Batch File,For Loop,Cmd,这个脚本有什么问题 @echo off SETLOCAL ENABLEEXTENSIONS SETLOCAL ENABLEDELAYEDEXPANSION set /P start= Input start : %=% set /P end= Input End : %=% for /l %%i IN (%start%,1,%end%) DO ( set num=0%%i set num=!num:~-2! echo wget "http://portal/exce

这个脚本有什么问题

@echo off

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

set /P start= Input start : %=%
set /P end= Input End : %=%

for /l %%i IN (%start%,1,%end%) DO (
    set num=0%%i
    set num=!num:~-2!
    echo wget "http://portal/excel!num!.xls"
)
pause
如果
Input start=01
Input End=06
,工作正常并下载excel文件。结果:

Input start : 01
Input End : 12
wget "http://portal/excel01.xls"
wget "http://portal/excel02.xls"
wget "http://portal/excel03.xls"
wget "http://portal/excel04.xls"
wget "http://portal/excel05.xls"
wget "http://portal/excel06.xls"
wget "http://portal/excel07.xls"
wget "http://portal/excel08.xls"
wget "http://portal/excel09.xls"
wget "http://portal/excel10.xls"
Press any key to continue . . .
Input start : 01
Input End : 08
Press any key to continue . . .
但是如果
Input start=01
Input End=08
或 如果
Input start=01
Input End=09
,则工作不正常,excel文件未下载。结果:

Input start : 01
Input End : 12
wget "http://portal/excel01.xls"
wget "http://portal/excel02.xls"
wget "http://portal/excel03.xls"
wget "http://portal/excel04.xls"
wget "http://portal/excel05.xls"
wget "http://portal/excel06.xls"
wget "http://portal/excel07.xls"
wget "http://portal/excel08.xls"
wget "http://portal/excel09.xls"
wget "http://portal/excel10.xls"
Press any key to continue . . .
Input start : 01
Input End : 08
Press any key to continue . . .

有人能解释一下吗?

前导零表示数字被解释为八进制。0-7没关系,但没有八进制8或9这样的数字。您已经在使用2个SET命令添加前导0,因此不要输入前导零。

前导零表示数字被解释为八进制。0-7没关系,但没有八进制8或9这样的数字。您已经在使用2个SET命令添加前导零,因此不要输入前导零。

这是一个解决方法:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION    
set start=101
set end=199

for /l %%i IN (%start%,1,%end%) DO (
     set num=!num:~-2!
    echo wget "http://portal/excel!num!.xls"
)
这是一个解决方法:

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION    
set start=101
set end=199

for /l %%i IN (%start%,1,%end%) DO (
     set num=!num:~-2!
    echo wget "http://portal/excel!num!.xls"
)