The syntax of the command is incorrect.

January 26, 2010 at 07:58:53
Specs: Windows 2K and XP
hi
I am writing long but simple batch. In some stage I got "The syntax of the command is incorrect." in few commands, I am sure are correct (e.g. "IF EXIST "%PROGRAMFILES%\Saveresults\saveresult.exe" ( ".
Same command works properly when written in Command Prompt window or in another batch.
I tried to resave the batch, also in other editors, several times , but the result is the same.

editor: Notepad++, ANSI encoding, DOS/Windows format

What the **********, could be the catch ?

10x for help

p.s.
would be anybody willing to review and "tune up" the batch?


See More: The syntax of the command is incorrect.

Report •

#1
January 26, 2010 at 08:21:40
1. replace ECHO OFF with ECHO ON, inside the script

2. Run the script, and copy-paste ALL the output in this thread. You may not be sure that the command you show, is the one with the trouble. Also, what about the variable, you are never sure it contains the correct value, other than actually running the code, and looking at the output. Trust me, you can look at code as much as you want, debugging is done by means of testruns...


Report •

#2
January 26, 2010 at 12:23:49
yeah just post your code. hopefully it's not too long...

Report •

#3
February 1, 2010 at 07:35:04
Yeah, viewing the code could really help ... the main diff. I know is the %%a versus %a things, when comparing lines between the one inside the batchfile versus the command line

Report •

Related Solutions

#4
February 10, 2010 at 01:46:18
thanks for the responses
Code is too long to be posted in here, but FYI problem was in remarks.
"::" remarks cannot be used before combined commands, and better not be used at all ("REM" only)

Report •

#5
February 10, 2010 at 02:24:50
You can use :: as the first 2 chars to indicate a remark line.

The batch interpreter sees it as an unaddressed label.


=====================================
Helping others achieve escape felicity

M2


Report •

#6
February 10, 2010 at 04:51:16
once again - you can, but if used before combined commands
:: some comment
if xxxxx (
aaa
bbb
ccc
)

you'll get incorrect syntax error

Report •

#7
February 10, 2010 at 05:13:18
Maybe you do; I don't.

======================
@echo off & setLocal EnableDELAYedeXpansion

:: this is a rem

if x equ x (
echo one
echo two
)


=====================================
Helping others achieve escape felicity

M2


Report •

#8
February 10, 2010 at 05:41:38

Report •

#9
February 10, 2010 at 06:13:39
I don't know what to tell you on this one, girls. The bat gives me no errors.

===============================

@echo off & setLocal EnableDELAYedeXpansion

:: this is a rem

if x equ x (
echo one
:: R2
: R3
echo two
)


=====================================
Helping others achieve escape felicity

M2


Report •

#10
February 10, 2010 at 12:21:54
here's where i always got them, immediately before a closing par:
if x equ x (
echo.x
::
)

error: ) was unexptected at this time.


Report •

#11
February 10, 2010 at 23:46:34
Hi nbrane,

Yep, for whatever goofy reason the compound won't take a label/rem, of either single or double colon, immediately preceding the closind paren.

Like so many things in windows, no idea why. It JUST DOES.

=================================
This doesn't work:
------------------------------
@echo off & setLocal EnableDELAYedeXpansion

:: this is a rem

if x equ x (
echo one
:: R2
: R3
echo two
: R4
)
==========================
This doesn't work either:
-----------------------------
@echo off & setLocal EnableDELAYedeXpansion

:: this is a rem

if x equ x (
echo one
:: R2
: R3
echo two
: R4
@echo off
)
==============================
But this does:
----------------------------
@echo off & setLocal EnableDELAYedeXpansion

:: this is a rem

if x equ x (
echo one
:: R2
: R3
echo two
: R4
echo off
)
==========================
sheesh


=====================================
Helping others achieve escape felicity

M2


Report •

#12
February 11, 2010 at 06:45:13
I think that from a programmer kind of view, you should not have labels inside complex IF (and ELSE) statements, and my intuition is that MS understood this as well, leaving very weird behaviour when you do.

Think about if, does this make sense ?

if %1==test :ref01


Report •

#13
February 11, 2010 at 08:01:06
it should just be treated as a "noOp", imo.

Report •

#14
February 12, 2010 at 00:38:00
"it should just be treated as a "noOp", imo."

90?


=====================================
Helping others achieve escape felicity

M2


Report •

#15
February 12, 2010 at 09:53:01
Yes, "ignore this and go on about your business"

Report •

#16
February 15, 2010 at 09:51:02
@echo off
goto l1
Really, I don't get the confusion here. If your batch script requires comments,
pick a different language, perhaps?
:l1
dir /b /s /a \*.com "%systemroot%\*.exe"
goto :eof
::     :V


Report •

Ask Question