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 集合上的批处理脚本错误/P_Batch File_Syntax Error_Netsh - Fatal编程技术网

Batch file 集合上的批处理脚本错误/P

Batch file 集合上的批处理脚本错误/P,batch-file,syntax-error,netsh,Batch File,Syntax Error,Netsh,我试图让脚本在检测到是否存在活动的internet连接时执行某些操作。这就是我想到的,但是当其中一个if语句没有运行时,我会得到一个语法错误 for /f "delims=" %%a in ('netsh interface show interface ^| find /I "Enabled Connected"') do @set netsh_output=%%a SET /P internet_connected="false" IF "%netsh_output%"==

我试图让脚本在检测到是否存在活动的internet连接时执行某些操作。这就是我想到的,但是当其中一个if语句没有运行时,我会得到一个语法错误

for /f "delims=" %%a in ('netsh interface show interface ^| find /I "Enabled        Connected"') do @set netsh_output=%%a

SET /P internet_connected="false" 
IF "%netsh_output%"=="Enabled        Connected      Dedicated        WiFi" (
  SET /P internet_connected="true"
)

IF "%netsh_output%"=="Enabled        Disconnected   Dedicated        Ethernet" (
  SET /P internet_connected="true"
)

if "%internet_connected%"=="true"(
  ECHO connected

)
当我有Wifi时,它可以工作,但当我没有以太网,第二个没有运行时,它会无缘无故地引发语法错误。难道我没有看到我应该看到的东西吗

C:\Users\ohheyit'sme\Desktop>IF "Enabled        Connected      Dedicated        WiFi" == "Enabled        Connected      Dedicated        WiFi" (SET /P internet_connected="true" )
true

C:\Users\ohheyit'sme\Desktop>IF "Enabled        Connected      Dedicated        WiFi" == "Enabled        Disconnected   Dedicated        Ethernet" (SET /P internet_connected="true" )
The syntax of the command is incorrect.
C:\Users\ohheyit'sme\Desktop>if "false"=="true"(
印刷错误 应该是

if "%internet_connected%"=="true" (
IF "%netsh_output%"=="Enabled        Connected   Dedicated        Ethernet" (

应该是

if "%internet_connected%"=="true" (
IF "%netsh_output%"=="Enabled        Connected   Dedicated        Ethernet" (

错误使用
set/p
如果要设置变量,不要求输入,请不要使用
/p
标志

set Foo=Bar
这将使用
Bar
字符串设置变量
Foo

set /p Foo=Bar

这会将变量
Foo
设置为用户输入。

Typo:
“true”
另一个输入错误:
启用了断开连接的专用以太网
。有一个错误。谢谢。我在我的代码中也发现了一些与您相同的错误,包括第二个if语句中的“断开连接”错误。除此之外,它现在正在工作:)