Search code examples
batch-filecmd

Why is MSG command not working in IF statement?


Sorry if this has been asked before, I couldn't find anything on this specifically. I'm a beginner at batch / CMD so this may be obvious.

The MSG command works fine in other batch scripts that I've written. But I'm writing a batch file that starts as below. (I've replaced the "magick" command with "testcommand" while testing.)

@echo off

REM ### check that the Image Magick program is installed
WHERE testcommand >nul 2>nul
IF %ERRORLEVEL% NEQ 0 (
    ECHO magick wasn't found 
    MSG You need to install ImageMagick
    PAUSE
    )

This should send a warning to the window and also show a popup alert using the MSG command. However, the output I get is:

magick wasn't found
you does not exist or is disconnected
Press any key to continue . . .

Why isn't the MSG command working? Do I need to escape the previous command? I've tried putting the text in quotes etc but there's no change.


Solution

  • Just type MSG /?

    For working correctly,you must add %username% to become MSG %username% You need to install ImageMagick

    @echo off
    REM ### check that the Image Magick program is installed
    WHERE testcommand >nul 2>nul
    IF %ERRORLEVEL% NEQ 0 (
        ECHO magick wasn't found 
        MSG %username% You need to install ImageMagick
        PAUSE
    )
    

    Help online for this command MSG