Page 1 of 1

The syntax of the command is incorrect.

Posted: 26 Jan 2010 09:57
by peterko
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?

Re: The syntax of the command is incorrect.

Posted: 26 Jan 2010 13:05
by aGerman
Would you write down an entire "faulty" line? Can't find any mistakes.

Regards
aGerman

Re: The syntax of the command is incorrect.

Posted: 27 Jan 2010 01:22
by peterko
Here it is completely.
~~~~~~~~~~~~~~~~~~

:: requirements
:: copy robocopy into %WINDIR%\system32\
:: copy pskill into %WINDIR%\system32\
:: copy doff into %WINDIR%\system32\

@echo off
cls
echo.
set debug_txt=

REM :: debug 0
REM ::@@@@@@@@@@@@@
REM if exist "%PROGRAMFILES%\Saveresults\saveresults.exe" @echo "%PROGRAMFILES%\Saveresults\saveresults.exe" found. > debug.log
REM if exist "%PROGRAMFILES%\Univer~1\FTR.exe" @echo "%PROGRAMFILES%\Univer~1\FTR.exe" found. >> debug.log
REM @pause
REM ::@@@@@@@@@@@@@
REM :: end of debug 0

::ERRORLOG
@echo %COMPUTERNAME% - %USERNAME% - %DATE% - %TIME% >%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end


path %WINDIR%\system32

::ERRORLOG
@echo PATH - %PATH% >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end

:: check administrative rights
@echo off
@net localgroup administrators | find "%USERNAME%" >NULL
if errorlevel 0 goto :isadmin
if errorlevel 1 goto :noadmin

REM :: debug 1
REM ::@@@@@@@@@@@@@
REM @echo. >> debug.log
REM @echo Errorlevel value is %ERRORLEVEL%
REM @echo Errorlevel value is %ERRORLEVEL% >> debug.log
REM @pause
REM ::@@@@@@@@@@@@@
REM :: end of debug 1

:: if logged on user is an administrator
:isadmin

::ERRORLOG - end
@echo in "isadmin" procedure >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end


if not exist %WINDIR%\system32\pskill.exe goto :pskill_error

if not exist %WINDIR%\system32\robocopy.exe goto :robocopy_error

if not exist %WINDIR%\system32\doff.exe goto :doff_error

REM :: debug 2
REM ::@@@@@@@@@@@@@
REM @echo. >> debug.log
REM @echo PSKILL found.
REM @echo PSKILL found. >> debug.log
REM @pause
REM ::@@@@@@@@@@@@@
REM :: end of debug 2

::variables

set net_path_xdm=\\netstore4\sdhint_log\savedata_xdm\
set net_path_int=\\netstore4\sdhint_log\integration\

:: sets value of date_p to yymmddhhmmss format for renaming files
:: value is stored in temp file, should be cleaned in the end
:: using doff utility
set currdate=%temp%\currdate_p.tmp
%WINDIR%\system32\doff.exe >%%currdate%%
set /p date_p=<%%currdate%%

::ERRORLOG
@echo net_path_xdm - %net_path_xdm% >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo net_path_int - %net_path_int% >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo date_p - %date_p% >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end


REM :: debug 3
REM ::@@@@@@@@@@@@@
REM @echo. >> debug.log
REM @echo net_path_xdm = %net_path_xdm%.
REM @echo net_path_xdm = %net_path_xdm%. >> debug.log
REM @echo net_path_xdm = %net_path_int%.
REM @echo net_path_xdm = %net_path_int%. >> debug.log
REM @pause
REM ::@@@@@@@@@@@@@
REM :: end of debug 3

::screen note -1
@cls
color 81
@echo "Stopping File Transmitter and SaveResults processes.
@echo " W A I T"
@echo 
:: end of screen note -1

:: U S E O L D pskill.exe V E R S I O N ! ! ! (no EULA)
::@TASKKILL /F /IM FTR.EXE
%WINDIR%\system32\pskill.exe FTR.EXE

:: wait 2 sec.
ping 127.0.0.1 -n 2 -w 1000 > nul

REM :: debug 4
REM ::@@@@@@@@@@@@@
REM @pause
REM ::@@@@@@@@@@@@@
REM :: end of debug 4



::@TASKKILL /F /IM SaveResults.exe
%WINDIR%\system32\pskill.exe SaveResult.exe


:: wait 2 sec.
ping 127.0.0.1 -n 2 -w 1000 > nul

::screen note -2
@cls
color 84
@echo "FTR and SaveResults are not running."
@echo.
@echo "Removing File Transmitter and SaveResults files.
@echo " W A I T"
@echo 
:: end of screen note -2

:: S A V E R E S U L T
if exist "%PROGRAMFILES%\Saveresults\saveresult.exe" (
del "%PROGRAMFILES%\Saveresults\*.*" /F /Q

:: wait 3 sec.
ping 127.0.0.1 -n 3 -w 1000 > nul

::remove startup shortcut
del "%ALLUSERSPROFILE%\Start Menu\Programs\Startup\sSAVE_RESULTS.*" /F /Q

:: wait 1 sec.
ping 127.0.0.1 -n 1 -w 1000 > nul

:: creating info file instead of deleted files
@echo "Original SaveResults application removed for DMZ network purposes." > "%PROGRAMFILES%\Saveresults\Saveresults_p.txt"

::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
::ERRORLOG - end

)

:: F T R
if exist "%PROGRAMFILES%\Univer~1\FTR.exe" (
"%PROGRAMFILES%\Univer~1\unins000.exe" /silent

:: wait 5 sec.
ping 127.0.0.1 -n 5 -w 1000 > nul

del "%PROGRAMFILES%\Univer~1\*.*" /F /Q

:: creating info file instead of deleted File Transmitter files
@echo "Original Universal File Transmitter application removed for DMZ network purposes." > "%PROGRAMFILES%\Univer~1\FTR_p.txt"

::ERRORLOG
@echo "F T R" if-procedure finished. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end

)

:: wait 3 sec.
ping 127.0.0.1 -n 3 -w 1000 > nul


::screen note -3
@cls
color 87
@echo "FTR and SaveResults removed."
@echo.
@echo "Signing report files.
@echo " W A I T"
@echo 
:: end of screen note -3

::Reports for XDM - signature + rename
if exist c:\saveres\*.* (
FOR /f "tokens=*" %%G IN ('dir c:\saveres /A:-D /B /S') DO (
echo %COMPUTERNAME% %DATE% %TIME% >>"%%G"
move "%%G" "%%G_%date_p%"
)
)
:: wait 3 sec.
ping 127.0.0.1 -n 3 -w 1000 > nul

::Reports for Integration 1 - signature + rename
if exist c:\int_srv\*.* (
FOR /f "tokens=*" %%G IN ('dir c:\int_srv /A:-D /B /S') DO (
echo %COMPUTERNAME% %DATE% %TIME% >>"%%G"
move "%%G" "%%G_%date_p%"
)
)
:: wait 3 sec.
ping 127.0.0.1 -n 3 -w 1000 > nul

::Reports for Integration 2 - signature + rename
if exist c:\int_db\*.* (
FOR /f "tokens=*" %%G IN ('dir c:\int_db /A:-D /B /S') DO (
echo %COMPUTERNAME% %DATE% %TIME% >>"%%G"
move "%%G" "%%G_%date_p%"
)
)

:: wait 3 sec.
ping 127.0.0.1 -n 3 -w 1000 > nul

::ERRORLOG
@echo Reports-signing procedure finished. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end

::screen note -4
@cls
color 8E
@echo "FTR and SaveResults removed."
@echo "Report files are signed and ready to be sent.
@echo.
@echo "Moving report files.
@echo " W A I T"
@echo 
:: end of screen note -4

:: wait 4 sec.
ping 127.0.0.1 -n 4 -w 1000 > nul

:: MKDIR for removed directories !!!!!!!!!!!!!!!!!!!!!!!!!!!

::Reports for XDM - moving
if exist c:\saveres\*.* (

::ERRORLOG
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo Robocopy XDM errorlog. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo --- NET_PATH_XDM = %net_path_xdm% >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
%WINDIR%\system32\robocopy.exe c:\saveres\ %net_path_xdm% /MOVE /E >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log (see note above)
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log

mkdir c:\saveres
)

::Reports for Integration 1 - moving
if exist c:\int_srv\*.* (

::ERRORLOG
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo Robocopy INT_SRV errorlog. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo --- NET_PATH_INT = %net_path_int% >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
%WINDIR%\system32\robocopy.exe c:\int_srv\ %net_path_int% /MOVE /E >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log (see note above)
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end


mkdir c:\int_srv
)

::Reports for Integration 2 - moving
if exist c:\int_db\*.* (

::ERRORLOG
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo Robocopy INT_DB errorlog. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo --- NET_PATH_INT = %net_path_int% >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
%WINDIR%\system32\robocopy.exe c:\int_db\ %net_path_int% /MOVE /E >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log (see note above)
@echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~>>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end


mkdir c:\int_db
)


:: creates log on local PC - file timestamp usable for BGinfo
@echo Report sent from %COMPUTERNAME% on %DATE% %TIME%. >> %HOMEDRIVE%\%COMPUTERNAME%_sent.log

::optional BGINFO refresh - timestamp of %COMPUTERNAME%_sent.log file can be used on screen display
if exist "%PROGRAMFILES%\bginfo_p\bginfo.exe"(
copy %WINDIR%\system32\user.bgi "%PROGRAMFILES%\bginfo_p" /y

:: wait 2 sec - pause cannot be used, as batch will run in parallel console sometimes (no interaction with actual user)
ping 127.0.0.1 -n 2 -w 1000 > nul

"%PROGRAMFILES%\bginfo_p\bginfo.exe" "%PROGRAMFILES%\bginfo_p\user.bgi" /timer:0

:: wait 2 sec - pause cannot be used, as batch will run in parallel console sometimes (no interaction with actual user)
ping 127.0.0.1 -n 2 -w 1000 > nul
)

:: variables cleaning
set net_path_xdm=
set net_path_int=
set currdate=
set date_p=
del %temp%\currdate_p.tmp /F /Q
:: net use Q: /delete

goto :eof


:: if logged on user is not an administrator
:noadmin

::ERRORLOG
@echo in "noadmin" procedure >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end

@cls
@color 4E
@echo.
@echo ~~~~~~~~~~~~~~~~~~~~
@echo "You are not an administrator on this workstation."
@echo "Call Peter or Stas !"
@echo ~~~~~~~~~~~~~~~~~~~~
:: wait 15 sec - pause cannot be used, as batch will run in parallel console sometimes (no interaction with actual user)
ping 127.0.0.1 -n 15 -w 1000 > nul
@echo Looged user was not has no admin rights. %DATE% %TIME%. >> %HOMEDRIVE%\%COMPUTERNAME%_sent.log
goto :eof


:: if pskill.exe was not copied into a %WINDIR%
:pskill_error

::ERRORLOG
@echo in "pskill" procedure >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end

@cls
@color 4E
@echo.
@echo ~~~~~~~~~~~~~~~~~~~~
@echo "PSKILL aplication is missing."
@echo "Call Peter or Stas !"
@echo ~~~~~~~~~~~~~~~~~~~~
:: wait 15 sec - pause cannot be used, as batch will run in parallel console sometimes (no interaction with actual user)
ping 127.0.0.1 -n 15 -w 1000 > nul
@echo Pskill application not found. %DATE% %TIME%. >> %HOMEDRIVE%\%COMPUTERNAME%_sent.log
goto :eof

:: if robocopy.exe was not copied into a %WINDIR%
:robocopy_error

::ERRORLOG
@echo in "robocopy" procedure >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end

@cls
@color 4E
@echo.
@echo ~~~~~~~~~~~~~~~~~~~~
@echo "ROBOCOPY aplication is missing."
@echo "Call Peter or Stas !"
@echo ~~~~~~~~~~~~~~~~~~~~
:: wait 15 sec - pause cannot be used, as batch will run in parallel console sometimes (no interaction with actual user)
ping 127.0.0.1 -n 15 -w 1000 > nul
@echo Robocopy application not found. %DATE% %TIME%. >> %HOMEDRIVE%\%COMPUTERNAME%_sent.log
goto :eof

:: if robocopy.exe was not copied into a %WINDIR%
:doff_error

::ERRORLOG
@echo in "doff" procedure >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
@echo. >>%HOMEDRIVE%\.reporter_error_%COMPUTERNAME%.log
::ERRORLOG - end

@cls
@color 4E
@echo.
@echo ~~~~~~~~~~~~~~~~~~~~
@echo "DOFF aplication is missing."
@echo "Call Peter or Stas !"
@echo ~~~~~~~~~~~~~~~~~~~~
:: wait 15 sec - pause cannot be used, as batch will run in parallel console sometimes (no interaction with actual user)
ping 127.0.0.1 -n 15 -w 1000 > nul
@echo Doff application not found. %DATE% %TIME%. >> %HOMEDRIVE%\%COMPUTERNAME%_sent.log
goto :eof

:eof

Re: The syntax of the command is incorrect.

Posted: 27 Jan 2010 08:52
by alan_b
You have a "code block" which starts with
if exist "%PROGRAMFILES%\Saveresults\saveresult.exe" (
and ends with
)

Within this code block you have illegal labels, i.e.
:: wait 3 sec
::remove startup shortcut
:: wait 1 sec.
:: creating info file instead of deleted files
::ERRORLOG
::ERRORLOG - end

Illegal labels mostly act like REM, but with some differences,
especially that DOS witll fall over when it finds them in code blocks,
and I vaguely recall a few other nasty gotchas for the unwary

I find on
http://www.robvanderwoude.com/comments.php
A true pitfall are code blocks, several commands grouped between parentheses and interpreted as a single command line by CMD.EXE!
IF EXIST C:\AUTOEXEC.BAT (
:: Comment line 1
ECHO Do something
:: Comment line 2
)
will result in an error message stating:
) was unexpected at this time.


Also, see
http://ss64.com/nt/rem.html

Alan

Re: The syntax of the command is incorrect.

Posted: 28 Jan 2010 03:37
by peterko
thanks and thanks, I checked and rechecked and never came to my mind that remarked lines could cause the problem
replacing them solve the error