Configuration of bat file - batch-file

Cd /d "D:\Test"
START mvn clean install -DskipTests
xcopy /s "D:\Test\brsint-web\brsint-webapp\target\Test.war" "D:\apache-tomcat-7.0_1.2Latest (2)\webapps" /Y
Cd /d "D:\apache-tomcat-7.0_1.2Latest (2)\bin"
START startup.bat
I am trying to write a bat file which has series of actions I wanted to perform. I want to trigger 3rd line after 2nd line execution. 2nd line is a maven build which generates war file it takes time to complete. Mean while 3rd line i.e., copy command is getting executed before War file is generated. Please help me resolve.

Trying to maintain the structure you had as best as possible, I would suggest perhaps this:
CD /D "D:\Test"
(Call mvn clean install -DskipTests) || GoTo :EOF
XCopy "D:\Test\brsint-web\brsint-webapp\target\Test.war" "D:\apache-tomcat-7.0_1.2Latest (2)\webapps" /S /Y
CD "D:\apache-tomcat-7.0_1.2Latest (2)\bin"
Call "startup.bat"
If the mvn command is not successful the script will end at that point!

You can use the /Wait or /W flag after the Start Command. This will spawn the process and wait for a Return or Exit code before continuing.
e.g.
Cd /d "D:\Test"
START /wait mvn clean install -DskipTests
xcopy /s "D:\Test\brsint-web\brsint-webapp\target\Test.war" "D:\apache-tomcat-7.0_1.2Latest (2)\webapps" /Y
Cd /d "D:\apache-tomcat-7.0_1.2Latest (2)\bin"
START /wait startup.bat

Related

Jboss 7 automatic deployment of EAR bat file

I am trying to automate my maven build and deployment process of the EAR in Jboss. I managed to write a bat file for the same which is given below.
ECHO OFF
RMDIR /S /Q .\deploy
call mvn clean install -D build=P,JB
call mvn clean install -D build=F,JB
#echo | call C:\Work\jboss-as-7.1.1.Final\bin\jboss-cli.bat --connect --controller=[my-machine-name]:9999 command=:shutdown
del /q C:\Work\jboss-as-7.1.1.Final\standalone\deployments\*.*
xcopy /s /y .\deploy\function\Jboss\*.ear C:\Work\jboss-as-7.1.1.Final\standalone\deployments
xcopy /s /y .\deploy\WorkFlowEngine\Jboss\*.ear C:\Work\jboss-as-7.1.1.Final\standalone\deployments
cd C:\Work\jboss-as-7.1.1.Final\bin
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\data" /s /q
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\log" /s /q
rmdir "C:\work\jboss-as-7.1.1.Final\standalone\tmp" /s /q
standalone.bat -bmanagement [my-machine-name] -b [my-machine-name] -c standalone-full-ha.xml
{code for check of deployment success/failure}
PAUSE
Here you can see that I am using the line
standalone.bat -bmanagement sbstjwsvm1509 -b sbstjwsvm1509 -c standalone-full-ha.xml
My requirement is that I want to check if the EAR was deployed successfully from my bat file.One way which I thought of is to check for .deplyed or .failed extension files in the Jboss deployment folder.I tried to write codes for the same but my code which is written below the above mentioned line is not getting executed.Is there any other means by which I can achieve this?Or what am I doing wrong in my bat file?Why is my code to check for deployment not getting executed?
Because the standalone.bat isn't executing in background and will be running the JBoss instance until you kill/stop it (ctrl+C signal or like you shutdown through jboss CLI). See this answer to get examples and details about you want to achive.
Since you are using maven, I suggest you to use jboss-as-maven-plugin.
Take a look the Usages, you will find commands to deploy/undeploy applications, resources, and to start/stop the server.
Then you could integrate the plugin execution to stop/clean in the maven clean phase and deploy/start on maven install phase using goals. See complex examples.
Thought of posting my solution here.
ECHO OFF
SET "JBOSS_DIR=C:\Work\jboss-as-7.1.1.Final"
SET "deployedAPP=MyApp.ear"
RMDIR /S /Q .\deploy
call mvn clean install -D build=P,JB
call mvn clean install -D build=F,JB
#echo | call %JBOSS_DIR%\bin\jboss-cli.bat --connect --controller=[mymachine_name]:9999 command=:shutdown
del /q %JBOSS_DIR%\standalone\deployments\*.*
xcopy /s /y .\deploy\function\Jboss\*.ear %JBOSS_DIR%\standalone\deployments
xcopy /s /y .\deploy\WorkFlowEngine\Jboss\*.ear %JBOSS_DIR%\standalone\deployments
cd %JBOSS_DIR%\bin
PING -n 61 -w 1 localhost >nul
START CMD /C CALL MyJboss.bat
SET count=0
:checkIfDeployed
if exist "%JBOSS_DIR%\standalone\deployments\%deployedAPP%.deployed" (
GOTO appDeployed
)
if exist "%JBOSS_DIR%\standalone\deployments\%deployedAPP%.failed" (
GOTO deployFailed
)
PING -n 6 -w 1 localhost >nul
GOTO checkIfDeployed
:appDeployed
PAUSE
EXIT
:deployFailed
SET /A count+=1
if %count% == 5 ( goto end )
#echo | call %JBOSS_DIR%\bin\jboss-cli.bat --connect --controller=[mymachine_name]:9999 command=:shutdown
PING -n 61 -w 1 localhost >nul
START CMD /C CALL MyJboss.bat
GOTO checkIfDeployed
:end
PAUSE
Used the line
START CMD /C CALL MyJboss.bat
to start JBoss in another cmd window.Now all my codes from below will get executed.

Command Prompt Scripting

This is going to be hard to explain, I'll try my best.
I'm using a shell scripting (Test Executor) in command prompt to automate our regression testing. However i'm stuck on one thing.
Basically I have to copy this dynamically created folder in a location into another folder after the automated script is done (in CMD via scripting)
:: create an achieve directory
#SET ACHIEVE_DIR=C:\Test Result\LOG_Files
mkdir "%ACHIEVE_DIR%"
xcopy /y /s /e "%TEST_SOURCE_DIR%"\*.* "%ACHIEVE_DIR%"
This will copy all the files in the TEST_SOURCE_DIR, but i only want this dynamically created folder which changes according to the date stamp (BUT this date stamp is calculated by second - so i can't use that as a variable).
For example: After i run a test it'll create a folder under lets say C:\temp\ another folder named "TEST RUN - _2014-06-30 15_48_01_"
So if go into C:\temp i'll find a folder named "TEST RUN - _2014-06-30 15_48_01_" along with other folders. BUT i only want to copy this dynamic folder into Test Result\LOG_Files
What we are given is that the starting string will always be "TEST RUN -" but the ending string will interchange according to the time to the second (BUT we cannot go by that since it is the second of the starting test result).
I found out if i am in command prompt and i type in "cd TEST RU" and hit tab it'll finish it for me "cd TEST RUN - _2014-06-30 15_48_01_" Is there a way to script this tab hit or something?
Thanks!
This should work in a batch file to isolate the folder:
If there are a number of folders starting with test run - then tell us.
#echo off
SET "ACHIEVE_DIR=C:\Test Result\LOG_Files"
cd /d "c:\temp"
for /d %%a in ("test run -*") do xcopy "%%a\*.*" "%ACHIEVE_DIR%\" /s/h/e/k/f/c
This code looks for a test folder as discussed in the comments:
#echo off
SET "ACHIEVE_DIR=C:\Test Result\LOG_Files"
cd /d "c:\temp"
for /d %%a in ("test run -*") do (
pushd "%%a"
for /d /r %%b in ("test*") do (
xcopy "%%b\*.*" "%ACHIEVE_DIR%\" /s/h/e/k/f/c
)
popd
)
This batch file should do the job:
#echo off
rem Find the directory starting with "TEST RUN -" created last in C:\Temp.
set ACHIEVE_DIR=C:\Test Result\LOG_Files
for /F "usebackq delims=" %%D in ( `dir "C:\Temp\TEST RUN -*" /AD /B /O-D /TC` ) do (
set TEST_SOURCE_DIR=%%D
goto CopyDir
)
echo No directory starting with "TEST RUN -" found in C:\Temp.
pause
exit /b
:CopyDir
rem Copy all files and subdirectories from last test run to achieve
rem directory whereby xcopy automatically creates the achieve directory.
xcopy /E /I /Q /S /Y "%TEST_SOURCE_DIR%" "%ACHIEVE_DIR%"
set ACHIEVE_DIR=
set TEST_SOURCE_DIR=
Read the Microsoft pages about
dir
for
xcopy
for details about the used parameters of those 3 commands.
Or execute in a command prompt window the commands
dir /?
for /?
xcopy /?
one after the other to get the shorter help for those 3 commands output in the window.

How to run any program with batch file from any specific location

I wrote a batch file for open a specific program but it is not working.I wrote this :
#echo off
C:\Windows\System32\cmd.exe /K "cd /d C:\Program Files (x86)\HTC\HTC Sync Manager\"
start HTCSyncManager.exe
When I run the batch file only this window come, program do not start. How to fix this
#echo off
For /r c: %%f in (path goes here /HTCsyncmanager.exe) do (
start "%%f"
"%%f"
)
Remove the invoking of cmd.exe. All that's doing is starting a new instance of the command processor, which is not what you need at all. (You probably don't need the start, either.)
#echo off
cd /d "C:\Program Files (x86)\HTC\HTC Sync Manager\"
HTCSyncManager.exe
#echo off
start "HTCSyncManager" "C:\Program Files\(x86)\HTC\HTC Sync Manager\HTCSyncManager.exe"
This will open HTCSyncManager.

CMD lines work fine but not in .bat file, it just instantly closes?

I tested the folowing lines in cmd ("ctrl + r" ---> "cmd")
and it works fine , but it doensn't work in .bat file , cmd comes up and then instantly closes
Here is my code
D:
cd D:\Java\Projects\Jasper\random-jasper-lib\
mvn clean install
cd D:\Java\Projects\Jasper\random-jasper\
mvn clean install
pause
How can I get the window to Stay open ?? (preferably even if there are errors)
mvn is a batch file.
If you call one batchfile from another, you have to use call otherwise the calling batch file will be terminated:
Using the /d for the cd command is also a good idea.
cd /d D:\Java\Projects\Jasper\random-jasper-lib\
call mvn clean install
cd /d D:\Java\Projects\Jasper\random-jasper\
call mvn clean install
pause
Why not with the pause command? -alternatively put cmd /k on the very last line of your script.
cd /d "D:\Java\Projects\Jasper\random-jasper-lib"
start /b "" "mvn" clean install
cd /d "D:\Java\Projects\Jasper\random-jasper"
start /b "" "mvn" clean install
cmd /k
try it like this:
PUSHD D:\Java\Projects\Jasper\random-jasper-lib\
mvn clean install
POPD
PUSHD D:\Java\Projects\Jasper\random-jasper\
mvn clean install
POPD
PAUSE
save as test.bat and execute it from cmd. that way it won't close the shell and you can see the errormessages

Running several batch-files in a batch-file

I'm making a batch-file which is supposed to run several batch-files. The problem is that it runs the first batch-file, and then quits
echo "Running SharePoint.Access\buildPackageAndCopy.bat..."
call SharePoint.Access\buildPackageAndCopy.bat
echo "Running SharePoint.Admin\buildPackageAndCopy.bat..."
call SharePoint.Admin\buildPackageAndCopy.bat
echo "Running Sharepoint.Levels\buildPackageAndCopy.bat..."
call SharePoint.Levels\buildPackageAndCopy.bat
I'm sure i have an enter-line between all the commands.
This is one of the batch-files I am running
call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
cd /d C:\src\SharePoint\
msbuild /p:IsPackaging=True
md c:\temp\_wsp
xcopy Core\bin\Debug\SharePoint.Core.wsp c:\temp\_wsp /y
xcopy Definitions03\bin\Debug\SharePoint.CustomDefinitions01.wsp c:\temp\_wsp /y
xcopy CustomLists02\bin\Debug\SharePoint.CustomLists01.wsp c:\temp\_wsp /y
xcopy Customs01\bin\Debug\SharePoint.CustomPresentation01.wsp c:\temp\_wsp /y
Try commenting out the content of the first batch file and see if the second one now runs. That way you'll know whether something in the first one is aborting it.

Resources