【问题标题】:create a .bat file and run multiple command with call创建一个 .bat 文件并通过调用运行多个命令
【发布时间】:2020-12-19 11:43:25
【问题描述】:

我想在批处理文件中运行一些命令并使用 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 install 完成后运行这个批处理文件时说

node js installed
if was unexpected at this time.

如何检查命令的成功和失败,然后运行其他命令。

【问题讨论】:

    标签: batch-file command npm-install


    【解决方案1】:

    试试这个:

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

    && 是有条件的,如果第一个命令成功,则运行下一个。 || 将成为 else 运算符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-09
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      相关资源
      最近更新 更多