Loops 批处理文件发布,接收“;文件名、目录名或卷标语法不正确;
运行批处理文件时,我收到以下错误 文件名、目录名或卷标语法不正确 我的批处理文件运行正常,但此错误会弹出25次,然后继续。我不知道我在这里错过了什么。下面是我的代码:Loops 批处理文件发布,接收“;文件名、目录名或卷标语法不正确;,loops,if-statement,goto,netsh,winpe,Loops,If Statement,Goto,Netsh,Winpe,运行批处理文件时,我收到以下错误 文件名、目录名或卷标语法不正确 我的批处理文件运行正常,但此错误会弹出25次,然后继续。我不知道我在这里错过了什么。下面是我的代码: ::This batch file is used to set a static IP and launch Windows Recovery Environment @setlocal enableextensions enabledelayedexpansion @echo off ::Setting Static IP
::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
===========================================================
任何帮助都会很好
谢谢
德里克试着取出
:
注释,并用rem
注释替换它们。我过去在使用像if
这样的内部控制结构时遇到过困难
请参阅以获取解释。事实上,对于那些由于某种原因不允许安装CygWin的cmd.exe
脚本编写者来说,这是一个难以置信的资源
如果失败,请注释掉
@echo off
,并查看出现错误时它在做什么。@Double,取出echo off
,您应该能够看到出现错误时正在运行的命令。