Attention when calling other batch files
Note that when a windows batch file issues a DOS command it will get back the control when that command finishes execution BUT it does not get the control again if it calls another batch file.Ex. (incorrect):
dir someOtherBatchFile.bat dirThe last "dir" command wont be executed because the batch file wont get the control after "someOtherBatchFile.bat" finishes execution.
The solution is using the call keyword:
Ex. (correct):
dir call someOtherBatchFile.bat dir
Variables
Ex.::text set someVar=hello ::the current folder set batchFolder=%CD% ::a folder set someFolder=C:\Programming\ ::access the vars ECHO %someVar% cd %batchFolder% dir cd %someFolder% dir
Pause
The pause command will wait for the user to press any key before the batch file proceeds.Just write "pause" in the batch file.
Comments
::This is a comment
Print text
@ECHO OFF ECHO HELLO WORLD
Batch Files examples
A batch file that calls DOS and ant commands to build and deploy a java project:cls @ECHO OFF set batchFolder=%CD% set FolderBookSearchXML=C:\Programming\ISFINAL\trab1\novo1\BookSearch set FolderWebService=C:\Programming\ISFINAL\trab2\Trabalho2\Webservice set FolderWSClient=C:\Programming\ISFINAL\trab2\Trabalho3\WebClient ::==================================== BookSearchXML =========================== ECHO * ECHO ******* CRIAR JAR DO BookSearchXML ******* ECHO * cd %FolderBookSearchXML% ::call ant clean call ant jar -q ECHO ******* COPIAR JAR PARA O WEBSERVICE ******* xcopy dist\*.jar %FolderWebService%\lib\ /Y/F ECHO ----- proximo passo: actualizar webservice ----- pause ::====================================== Webservice =========================== ECHO * ECHO ******* GERAR ARTEFACTOS DO WEBSERVICE ******* ECHO * cd %FolderWebService% call ant wsgen-BookSearchWS -q ECHO ******* DEPLOY WEBSERVICE ******* call ant run-deploy -q ECHO ----- proximo passo: actualizar cliente do webservice ----- pause ::================================ Cliente do webservice ======================== ECHO * ECHO ******* GERAR ARTEFACTOS DO CLIENTE DO WEBSERVICE ******* ECHO * cd %FolderWSClient%\src\java ::wsimport -verbose -keep http://localhost:8080/BookSearchWebservice/BookSearchWS?wsdl wsimport -keep http://localhost:8080/BookSearchWebservice/BookSearchWS?wsdl del mywspackage\*.class ECHO ******* DEPLOY DO CLIENTE DO WEBSERVICE ******* cd %FolderWSClient% ::call ant clean call ant run-deploy -q ::return to starting directory cd %batchFolder%
No comments:
Post a Comment