如何在命令提示符中设置循环的时间约束?

时间:2014-07-08 17:53:28

标签: for-loop cmd

我正在使用命令提示符从API中提取信息并出现问题。我的命令提示码非常快:
FOR /L %i IN (0,100,3643453) DO echo curl -glob "api.fda.gov/drug/event.json?&search=receivedate:[20040101+TO+20150101]&limit=100&skip=%i"
 但现在我面临每分钟提取次数限制的问题。我相信你每分钟只能从API获取100套,所以有没有办法在循环中编写一个限制,在命令提示符下每分钟运行100次?

2 个答案:

答案 0 :(得分:0)

GNU sleep命令应该是您正在寻找的。

完全未经测试,但它应该是这样的:

FOR /L %i IN (0,100,3643453) DO echo curl -glob "api.fda.gov/drug/event.json?&search=receivedate:[20040101+TO+20150101]&limit=100&skip=%i; sleep .6s"

如果您正在寻找MS的方法,您可能会研究“Windows 2003 Resource Kit tools”

答案 1 :(得分:0)

对于本机批量版本,您可以尝试一下

@echo off

setlocal enableextensions enabledelayedexpansion

set "counter=0"
for /f "tokens=2 delims=:" %%a in ("%time%") do set "minute=%%a"

FOR /L %%i IN (0,100,3643453) DO (
    echo curl -glob "api.fda.gov/drug/event.json?&search=receivedate:[20040101+TO+20150101]&limit=100&skip=%%i"
    for /f "tokens=2,3 delims=:" %%a in ("!time!") do if %%a equ !minute! (
        set /a "counter+=1"
        if !counter! geq 100 (
                echo Limit reached, waiting ...
                set /a "wait=60-%%b+2"
                ping -n !wait! localhost >nul 2>nul 
                set "counter=0"
                for /f "tokens=2 delims=:" %%c in ("!time!") do set "minute=%%c"
        )
    ) else ( set "counter=1" & set "minute=%%a" )
)

endlocal