Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.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
Batch file 我的批处理文件没有循环?_Batch File - Fatal编程技术网

Batch file 我的批处理文件没有循环?

Batch file 我的批处理文件没有循环?,batch-file,Batch File,我是新手,我正在尝试一个我在Youtube上看到的基本例子: @echo off echo this little program helps you to refresh a website pause cls echo but first we have to do some preferences pause cls echo please enter the website name here set /p website= cls echo please enter the time

我是新手,我正在尝试一个我在Youtube上看到的基本例子:

@echo off
echo this little program helps you to refresh a website 
pause
cls
echo but first we have to do some preferences
pause
cls
echo please enter the website name here
set /p website=
cls
echo please enter the time between refreshes
set /p time=
cls
echo Set limited or unlimited refresh
set /p refresh=
if'%refresh%'=='1' goto :once
if'%refresh%'=='0' goto :unlimited
cls

:once
cls
echo Preferences finished
pause
timeout /t %time% /nobreak
start %website%
exit

:unlimited
cls
echo Preferences finished
pause
:again
timeout /t %time% /nobreak
start %website%
goto :again
此代码应要求用户提供网站和刷新时间,它将通过在IE(Internet Explorer)中重新打开该网站来刷新该网站,但我有两个问题:

  • 如果输入0或“0”,循环将不工作,它将只执行一次并退出.bat
  • 有没有一种方法可以在不重新打开新选项卡的情况下刷新页面,例如只刷新当前选项卡

  • 脚本中有一些语法错误


    退出
    命令
    EXIT
    退出脚本。你可能想把它换成别的东西


    IF
    语句 稍微有点不正确,因为
    if
    和比较器之间缺少空格。此外,使用双引号可以确保它成功地与包括空格在内的值进行比较

    if "%refresh%"=="1" goto :once
    

    未定义输入 如果变量
    %refresh%
    不是1或0,它将转到
    :once
    并在那里执行代码


    刷新网页 将此脚本另存为
    Refresh.vbs
    ,并将其与批处理文件放在同一文件夹中


    然后,当您想要刷新网页时,请执行
    cscript//nologo refresh.vbs

    提示:
    exit
    commandexit应该工作:once以便它执行一次,如果我先定义:unlimited,然后定义:once是否更好?否。。这是同样的事情。好吧,我交换了定义:一次是结束,现在它无限循环。谢谢你对页面刷新有什么想法吗?检查我的答案。刷新太快了,没有加载页面。cmd框出现口吃,页面一直在加载。然后,当您输入
    时间时,输入一个更大的数字。是的,我修复了它,这是我的一个错误。很抱歉非常感谢你。
    
    if "%refresh%"=="1" goto :once
    
    Set WshShell = WScript.CreateObject("WScript.Shell") 
    WshShell.AppActivate("Chrome")
    WshShell.SendKeys "{F5}"