Windows BAT脚本中调用BAT脚本导致CMD退出的问题

遇到bat中调用bat或执行mvn命令时,必须使用call调用,否则会执行到bat或mvn以后,cmd就退出了,后面的内容不会执行到。

下面是我的一个例子:

@ECHO OFF

rem set args
set DIR_BASE="%CD%"
set DIR_DIST="%CD%\dist"
set RESULT="%CD%\res.txt"

rem cleans at first
if exist %RESULT% del /F %RESULT%
if exist %DIR_DIST% rd /s/q %DIR_DIST%
echo "========0 reset finished."
echo "========0 reset finished." >> %RESULT%

cd %DIR_BASE%
call mvn clean install >> %RESULT%
echo "========1 compile finished."
echo "========1 compile finished." >> %RESULT%

rem pkg server
cd %DIR_BASE%
mkdir %DIR_DIST%
cd demo\run
winrar a -r demo.zip *
if exist demo.zip (
  move /Y demo.zip %DIR_DIST% >> %RESULT%
  
  echo "========2 pkged---"
  echo "========2 pkged---" >> %RESULT%
) else (
  echo "========ERROR: demo.zip not found."
  echo "========ERROR: demo.zip not found." >> %RESULT%
)

rem pkg ui
cd %DIR_BASE%
if exist demoUi\target\demo.war (
  copy /Y demoUi\target\demo.war %DIR_DIST% >> %RESULT%
  
  echo "========3 demo.war pkg ok---"
  echo "========3 demo.war pkg ok---" >> %RESULT%
) else (
  echo "========ERROR: demo.war not found."
  echo "========ERROR: demo.war not found." >> %RESULT%
)

rem calc md5
cd %DIR_DIST%
call md5util >> %RESULT%
echo "========4 finish md5 calc---"
echo "========4 finish md5 calc---" >> %RESULT%

cd %DIR_BASE%
echo "========5 all finished!"
echo "========5 all finished!" >> %RESULT%

rem reset args
set DIR_BASE=
set DIR_DIST=
set RESULT=

PAUSE

你可能感兴趣的:(Windows,开发,常见问题)