Babu R
Babu R

Reputation: 1035

How to solve syntax of the command is incorrect error in batch file?

I am using the following code in batch file. I am getting "Syntax of the command is incorrect " error.

Please help me how to solve this.

Thanks in advance...

@echo off
For /F "tokens=1 delims==" %%A IN (proconfig.properties) DO 
( 
IF "%%A"=="dbUsername" 
set dbUsername=%%B
) 

echo %dbUsername%

pause

Upvotes: 0

Views: 9604

Answers (2)

MC ND
MC ND

Reputation: 70923

Your problem is that the opening parenthesis for the block of code after the do clause must be in the same line that the do. And it is the same for the if command. Also, to retrieve two tokens with the for command, it is necesary to indicate it in the tokens clause

@echo off
For /F "tokens=1,2 delims==" %%A IN (proconfig.properties) DO ( 
    IF "%%A"=="dbUsername" set dbUsername=%%B
) 

echo %dbUsername%

pause

Upvotes: 3

Alex
Alex

Reputation: 917

There's supposed to be a ( right after the DO and increment the tokens. Also, your IF statement need parenthesis as well. See below:

@echo off
setlocal ENABLEDELAYEDEXPANSION
For /F "tokens=1-2 delims==" %%A IN (proconfig.properties) DO (
    IF "%%A"=="dbUsername" (
        set dbUsername=%%B
    )
) 

echo %dbUsername%

pause 

Upvotes: 2

Related Questions