Announcement

Collapse
No announcement yet.

"The syntax of the command is incorrect." error in batch

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • "The syntax of the command is incorrect." error in batch

    hi
    I am writing long but simple batch. In some stage I got "The syntax of the command is incorrect." in few commands, but I am sure they 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?
    Attached Files

  • #2
    Re: "The syntax of the command is incorrect." error in batch

    You use :: within grouped commands (joined between parenthesis). Try to replace those with rem.

    e.g.
    Code:
    :: S A V E R E S U L T
    	if exist "%PROGRAMFILES%\Saveresults\saveresult.exe" (
    		del "%PROGRAMFILES%\Saveresults\*.*" /F /Q
    		
    		rem wait 3 sec.
    		ping 127.0.0.1 -n 3 -w 1000 > nul
    		
    		rem remove startup shortcut 
    		del "%ALLUSERSPROFILE%\Start Menu\Programs\Startup\sSAVE_RESULTS.*" /F /Q
    		
    		rem wait 1 sec.
    		ping 127.0.0.1 -n 1 -w 1000 > nul
    		
    		rem creating info file instead of deleted files
    		@echo "Original SaveResults application removed for DMZ network purposes." > "%PROGRAMFILES%\Saveresults\Saveresults_p.txt"
    		
    		rem ERRORLOG
    			@echo "S A V E R E S U L T" if-procedure finished. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
    			@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
    		rem ERRORLOG - end
    
    	)
    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: "The syntax of the command is incorrect." error in batch

      You saved me miles of nerves...
      Yes it solved the problem, even I got no idea WHY ?
      It's just "for eye", that I prefer "::" instead of "REM", but what are the differences between them ?

      Thanks once again.

      Comment


      • #4
        Re: "The syntax of the command is incorrect." error in batch

        Originally posted by peterko View Post
        Yes it solved the problem, even I got no idea WHY ?
        It's just "for eye", that I prefer "::" instead of "REM", but what are the differences between them ?
        Grouped commands (between parentheses) are interpreted as a single command-line (where the "Carriage return+ Line feed" is interpreted as "&" between the commands).
        Now, double Colon marks will cause skipping the rest of the command-line. That is basically what happens - so you cannot use double Colon on a singe command-line and therefore you cannot use the doubled colon in grouped commands.


        There are two ways to Comment-out lines in a batch.
        Start the comments with the rem command
        or
        Start the comments with a doubled colon

        The Double Colon is infact a "label" for the batch (labelnames start with a singel colon), the label is made invalid by doubling the colon. So what happened is that you've converted the next part of the 'grouped commands' all to one label, including the closing parenthese.

        The advantage of using :: over the rem command is mainly for performance reasons,,
        As you may already know, the command interpreter (Cmd.exe) process the rem statement in a batch file, while it skips a label if there is not a Goto statement defined to this specific line.
        The command interpreter reads the batch file and executes *one* command-line at the time then it reads the batch file again in order to process the next command-line, ect. This means each line of remarks starting with rem causes one extra reread of the batch file.

        I agree, I prefere using the Double Colon myself mostly "for eye" and also because the line does not echo before @echo off.
        But if I cannot use the double colon then I use something like rem ### instead or, REM :: like you did somewhere else in your batch.


        (read also: http://www.robvanderwoude.com/comments.php)


        \Rems
        Last edited by Rems; 28th January 2010, 09:47.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment

        Working...
        X