create a .bat file and run multiple command with call

Viewed 787

I want to run some command in the batch file and use the if statement.

@echo off
call npm install
echo node js instaled
if not errorlevel 1 (
    call composer install
    if not errorlevel 1 (
        echo commands run success.
    ) else (
        echo please install composer and then run this batch again.
    )
) else (
    echo you have not nodejs in your system. please install nodejs.
)

when I run this batch file after npm install completed say

node js installed
if was unexpected at this time.

how I can check success and unsuccess of the command and then run other commands.

1 Answers

Give this a try:

@echo off
call npm install && (
    echo node js installed
    call composer install && (
       echo Composer installed
    ) || echo composer install failed
) || echo Nodejs install failed

&& is conditional, if the first command was successful, then run the next. || is then becoming the else operator.

Related