运行批处理文件时,我收到以下错误 “文件名,目录名称或卷标签语法不正确”
我的批处理文件运行正常,但此错误弹出25次然后继续。我无法弄清楚我在这里缺少什么。以下是我的代码:
::This batch file is used to set a static IP and launch Windows Recovery Environment
@setlocal enableextensions enabledelayedexpansion
@echo off
::Setting Static IP Address & DNS Address
netsh interface ipv4 set address "Local Area Connection" static 10.11.111.110 255.255.255.0 10.11.111.249 1
netsh interface ipv4 set dns "Local Area Connection" static 10.11.101.1 primary
::Verify Network Connection
:chklink
set ipaddr=10.11.107.20
set oldstate=neither
set state=down
for /f "tokens=5,7" %%a in ('ping -n 1 !ipaddr!') do (
if "x%%a"=="xReceived" if "x%%b"=="x1," set state=up
)
if not !state!==!oldstate! (
echo.Link is !state!
set oldstate=!state!
)
REM ping -n 2 127.0.0.1 >nul: 2>nul:
SET answer=!state!
IF %answer%==up (
goto recovery
) ELSE (
IF %answer%==down (
::Set static address on NIC 2 if NIC 1 failed
netsh interface ipv4 set address "Local Area Connection 2" static 10.11.111.110 255.255.255.0 10.11.111.249 1
netsh interface ipv4 set dns "Local Area Connection 2" static 10.11.101.1 primary
goto chklink
)
)
::Launch Windows Recovery Environment
:recovery
cls
x:\sources\recovery\recenv.exe
exit
=============================================== ============
任何帮助都会很棒!
谢谢!
德里克
答案 0 :(得分:1)
尝试取出::
条评论并将其替换为rem
条评论。过去我使用if
等内部控制结构时遇到了困难。
有关说明,请参阅here。实际上whole site对cmd.exe
脚本编写者来说是一个令人难以置信的资源,由于某种原因,他们不允许安装CygWin。
如果不这样做,请注释@echo off
并查看出现这些错误时的操作。