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?
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...
yeah just post your code. hopefully it's not too long...
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
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)
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 felicityM2
once again - you can, but if used before combined commands
:: some comment
if xxxxx (
aaa
bbb
ccc
)
you'll get incorrect syntax error
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 felicityM2
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 felicityM2
here's where i always got them, immediately before a closing par:
if x equ x (
echo.x
::
)error: ) was unexptected at this time.
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 felicityM2
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
it should just be treated as a "noOp", imo.
"it should just be treated as a "noOp", imo." 90?
=====================================
Helping others achieve escape felicityM2
Yes, "ignore this and go on about your business"
@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
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |