我想在批处理文件中运行一些命令并使用if语句。
@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.
)
当我在npm安装完成后运行这个批处理文件时,说
node js installed
if was unexpected at this time.
如何检查命令的成功和失败,然后运行其他命令。
尝试一下:
@echo off
call npm install && (
echo node js installed
call composer install && (
echo Composer installed
) || echo composer install failed
) || echo Nodejs install failed
&&
是有条件的,如果第一个命令成功,则运行下一个命令。则CCD_ 2变成CCD_。