批量关闭窗口用户输入

时间:2014-10-18 00:11:34

标签: windows batch-file

我正在制作一个批量互联网浏览器,但是当我试图让某个人关闭"关闭"在,它试图连接到一个名为close的网站。这是迄今为止的代码:

@echo off
color 1f
:a
echo -= batch browser-=
echo type close in the website box to close
set /p id="Enter website(that starts with http-://-www.): " %=%
echo loading site......
ping localhost >nul
echo Press any key to open.....
pause >nul
If %id% == "close" goto close
start firefox.exe %id%
echo website open. Press any key to go back to the browser
pause >nul
goto a
:close
exit

有人可以帮忙吗?如果是这样,谢谢:)

3 个答案:

答案 0 :(得分:1)

%id%声明中引用if

If "%id%" == "close" goto close

答案 1 :(得分:1)

你必须与平等两边的引号保持一致并丢失空格。

If %id% == "close" goto close

表示

if close == "close" goto close

所以

if close<space>==<space><quote>close<quote> goto close

答案 2 :(得分:1)

报价包含在比较中。您的IF语句在右侧有引号,但在左侧没有。将其更改为:

If "%id%" == "close" goto close

您可能希望添加/I选项,以防用户使用大写。

此外,如果使用延迟扩展,您的代码将更安全。

@echo off
setlocal enableDelayedExpansion
color 1f
:a
echo -= batch browser-=
echo type close in the website box to close
set /p id="Enter website(that starts with http-://-www.): " %=%
echo loading site......
ping localhost >nul
echo Press any key to open.....
pause >nul
If /I "!id!" == "close" goto close
start firefox.exe !id!
echo website open. Press any key to go back to the browser
pause >nul
goto a
:close
exit
相关问题