2

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.