我正在开发一个angular-android应用程序,因此必须在cmd中运行一些命令。由于命令需要花费一些时间才能运行,因此我的系统具有最低限度的规范,因此我必须继续对其进行监视。为了减少时间并专注于其他事情,我在批处理文件中添加了一些命令。例如
ng build
cordova clean browser
cordova build browser
cordova run browser
我放置了以上命令并将其保存为批处理文件。当我运行此文件时,它仅执行第一个命令ng build
,不会自动跳到第二行。以前我使用mac,因为我将它们另存为.sh
文件,并且在执行它们时,其中的所有命令均成功执行。我应该怎么做才能在批处理文件中自动执行下一个命令?谢谢。
答案 0 :(得分:3)
类似这样:
@echo off && setlocal enabledelayedexpansion
call ng &&^
call cordova clean browser &&^
call cordova build browser &&^
call cordova run browser
endlocal && goto :EOF
rem :: or in one line ::
call ng && (call cordova clean browser && (call cordova build browser &&(call cordova run browser)))
@echo off && setlocal enabledelayedexpansion
set "_run=ok"
call ng && for %%i in ("clean browser","build browser","run browser
)do if "!_run!" == "ok" call cordova %%~i || set "_run="
endlocal && goto :EOF
在 bat / cmd 中,您可以使用 &, |, && 和|| ,还将其组合 ...
commandA & commandB Run commandA and then run commandB commandA && commandB Run commandA, if it succeeds then run commandB commandA || commandB Run commandA, if it fails then run commandB commandA && commandB || commandC If commandA succeeds run commandB, if it fails commandC
答案 1 :(得分:0)
在每个命令之前添加开始
start ng build
start cordova clean browser
start cordova build browser
start cordova run browser