What is the syntax error in this batch script?
I am trying to get a substring from a string and check if it is equal to "System". I am getting the string from %%a. When I run the script I get the error "unexpected (". If I remove the lines inside the for loop ("set _varsub ...) the error goes away. So I think there is some syntax error with my substring command. Can anyone tell me?
for /f "tokens=1,3,4,* delims=: " %%a in ('开发者_运维知识库e:\DeployTools\handle.exe %deploymentdir%\%%i ^| findstr /i pid: ') do @(
set _varsub=%%a
set _varsub=%_varsub:~0,6%
if not %_varsubstring%==System (
// do something
)
Like thescottknight wrote, your code will fail as the variable isn't defined,
but even then it would fail as expanding inside of brackets doesn't work with percentd.
In your case you should use the delayed expansion with exclamation marks.
set _varsub=%%a
set _varsub=!_varsub:~0,6!
Try putting quotes around the variables in the if statement,
if not '%_varsubstring%'=='System' (...
the unexpected error is because _varsubstring is undefined at that point, so the line evaluates to:
if not ==System (
精彩评论