Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Why this returns ELSE is not recognized command
Message
De
23/02/2021 15:42:34
 
 
Information générale
Forum:
Windows
Catégorie:
Commandes DOS
Divers
Thread ID:
01678538
Message ID:
01678539
Vues:
39
J'aime (1)
>Hi everybody,
>
>I'm trying to figure out why I am getting this error from SQL Server Agent job which is supposed to execute a batch file.
>
>End of the batch file is this:
>
>
>IF NOT EXIST %Main_PATH%File_Extract\Status\File_Extract_Main%JobNbr%_OK.txt (
>	REM powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-EventLog -LogName 'VACCN' -Source 'DataRepo' -EventID 5120 -EntryType Error -Message 'Fatal error in VA Extract process.'"
>	REM call %Main_PATH%EventWriterWriter\Scripts\release\EventWriter.exe %JobNbr% "DR_101" "batchfile" "Fatal error in VA Extract process."
>	EXIT 11
>)
>ELSE (
>	REM powershell -NoProfile -ExecutionPolicy Bypass -Command "Write-EventLog -LogName 'VACCN' -Source 'DataRepo' -EventID 5100 -EntryType Information -Message 'Successful completion of Extract Job 89.'"
>	REM echo “Successful completion”
>	EXIT
>)
>
>The error in Agent is the following (end of the step):
>
>'ELSE' is not recognized as an internal or external command, operable program or batch file. Process Exit Code 9009. The step failed.
>
>Do you see what may be wrong with the bat file - it seems OK to me.

Have you tried putting the ELSE on the same line as the closing parenthesis of the THEN part?
IF ....  (
    ...
) ELSE (
   ...
)
part of the help information if I type "if /?" on the command line in CMD.EXE
...
The ELSE clause must occur on the same line as the command after the IF.  For
example:

    IF EXIST filename. (
        del filename.
    ) ELSE (
        echo filename. missing.
    )

The following would NOT work because the del command needs to be terminated
by a newline:

    IF EXIST filename. del filename. ELSE echo filename. missing

Nor would the following work, since the ELSE command must be on the same line
as the end of the IF command:

    IF EXIST filename. del filename.
    ELSE echo filename. missing

The following would work if you want it all on one line:

    IF EXIST filename. (del filename.) ELSE echo filename. missing
...
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform