Make command line stay open when running a bat file - ant

I want my batch file to stay open after processing is complete.
Here is my code:
set CLASSPATH=C:\XSLTANT\examples\word_transform\apache-ant-1.8.1\bin
set PATH=%CLASSPATH%
ant >> transform.log
echo "See transform.log for results"
pause
It closes instantly after it runs the ant build. Any ideas?
Thanks.

Change the line:
ant >> transform.log
to
CALL ant >> transform.log
This is required when running one batch file from another.

Related

How can I get a long running PreBuildEvent to output data while its running, instead of after?

I have a visual studio MVC project and I use NPM and Bower. I restore my NPM and Bower packages as part of my build process via a pre-build command line, so the people that use the project don't need to know about npm install, etc.
Unfortunately, for whatever reason, the output is not rendered to the output window until after the package restore has finished. When building a project for the first time, this can take a very long time and I don't want to leave my users hanging, waiting for visual studio to respond.
Is there a way I can set up my pre-build command line prompt to write to the output as it runs, rather than after it runs?
csproj call to run the command
<PropertyGroup>
<PreBuildEvent>
cd "$(ProjectDir)"
echo "generating output for the output window prior to running the long running process"
dir
echo "now running long running task"
call pre-build.bat $(ConfigurationName)
</PreBuildEvent>
</PropertyGroup>
As you can see, I have some debug output in there, a couple of calls to "echo" and a dir call. I would expect to see those commands output to the output window prior to the long running task, but this doesnt happen. Instead I just see the following output until after the package restore runs
1>------ Build started: Project: MyProject, Configuration: Debug Any CPU ------
Because I'm not seeing output from the echo's and the dir, I'm thinking there is either a different way to run this task, or VS / MsBuild just doesnt support showing the output I want until after the task is run. Does anyone know how to set it up to write the output as the task runs?
Use the Target & Message elements:
<Target Name="UserMessage" BeforeTargets="Build">
<Message Text="Your message here" />
</Target>

Jenkins deleting batch file before it's completed

I'm running Jenkins on a Server 2012 VM, and I'm noticing that some of my projects are being marked as incomplete when they are successful. I am getting the error 'The batch file cannot be found.' The problem, from what I can tell, is that the batch file Jenkins is creating to run my project is being deleted before it's completed. I'm migrating from a windows 7 box where this issue doesn't happen.
I've been able to watch as the batch file is created in C:\Users\164016\AppData\Local\Temp\ and then it's deleted before the batch file completes. I'm even able to open the batch file before it's deleted.
I've tried placing the Call command at the beginning of the command, but that doesn't resolve the issue.
The LaunchPad.exe command is a custom made script designed to return exit codes from Excel vba macros.
Please let me know if you have any suggestions.
Here is the log:
Building remotely on (164016) Remote Computer in workspace C:\TEMP\Jenkins Slave\workspace\Weekly Claim Edit WQ Age
[Weekly Claim Edit WQ Age] $ cmd /c call C:\Users\164016\AppData\Local\Temp\hudson3188220465265190989.bat
C:\TEMP\Jenkins Slave\workspace\Weekly Claim Edit WQ Age>"O:\Analytics Team\Tasks\Automation Components\Ryan\C#\Launch Pad\LaunchPad\LaunchPad\bin\Debug\LaunchPad.exe" "C:\Program Files (x86)\Quest Software\Toad for Data Analysts 2.7\Toad.exe" -batch=true "O:\Analytics Team\Tasks\Automation Components\Cindy\TAS\Claim_Edit_WQ_Age.tas" "O:\Analytics Team\Tasks\Claim Edit WQ Age\Claim_Edit_WQ_Age.xlsm"
LaunchPad Start Time: 10.7.2014 9:49:10 AM
Time before Stopping Programs: 60 min
Program: "C:\Program Files (x86)\Quest Software\Toad for Data Analysts 2.7\Toad.exe"
Arguments: "-batch=true" "O:\Analytics Team\Tasks\Automation Components\Cindy\TAS\Claim_Edit_WQ_Age.tas"
vba File: "O:\Analytics Team\Tasks\Claim Edit WQ Age\Claim_Edit_WQ_Age.xlsm"
vba Exit File: O:\Analytics Team\Tasks\Claim Edit WQ Age\Claim_Edit_WQ_Age.txt
Report Completed: 10/7/2014 9:50:28 AM 164016 O:\Reports\EPIC\Epic Claim Edit WQ\20141007 Claim Edit WQ Age.xlsx
Exiting LaunchPad: No Errors Detected: 0
The batch file cannot be found.
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
I had a very similar problem. I was running a job in Jenkins that was calling a specialized internal program and causing the "batch file not found" error. It turns out there was a del %TEMP%\*.* /q command in one of the batch files being run. This was deleting all of the Jenkins temporary batch files in the middle of the job and causing the error.
The simple solution is to simply relocate the Jenkins temp folder. This can be done by adding a command line option to your Jenkins startup script. My startup script looks like: java -XX:MaxPermSize=1024m -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -Djava.io.tmpdir=C:\Users\!!My_user_name!!\Desktop\Jenkins_Temp -jar jenkins.war
The important part I added was the -Djava.io.tmpdir=C:\Users\!!My_user_name!!\Desktop\Jenkins_Temp option (Removed my user name for privacy reasons.) This fixed the problem. Don't forget to replace my path with with a valid path name for your system.
The command line option should be added to both the master and slave startup scripts for proper operation.
You've got something else at play here...
When you configure Execute Windows batch command build step, it creates a temporary batch file that Jenkins then executes.
The execution of the temporary batch file starts at:
[Weekly Claim Edit WQ Age] $ cmd /c call C:\Users\164016\AppData\Local\Temp\hudson3188220465265190989.bat
and it finishes at:
Build step 'Execute Windows batch command' marked build as failure
The temporary batch file hudson3188220465265190989.bat would be deleted after that last line.
Your error The batch file cannot be found. happens before that line. So, it's not the Jenkins temporary batch file that cannot be found, but something else.
Unless you provide the content of your Execute Windows batch command, it's difficult to guess what else could be the problem.

Ant inside Robot Framework

Robot framework is generic keywords base testing framework. So can we use Ant task as a keyword in robot?
If yes what are the possible ways?
You can't use directly a Ant Task as a Robot keyword, but you can use Run Process keyword from the Process Library to launch the Ant command line you want to run:
*** test cases ***
my test
Run Process ant command line to launch
We can use "Run And Return Rc And Output" keyword from "OperatingSystem" Library
*** test cases ***
Test Ant
${RC} ${Output} Run And Return Rc And Output ant -f "antFile name"
where you need to set ANT_HOME and also set ANT in path variable
as
set PATH=%PATH%;%ANT_HOME%/bin
which will then run the ant task defined in ant file.
#{Flag}= Run And Return Rc And Output run.py
should Contain #{Flag} Camera Locked
The result will be saved in Flag variable and the next line will search for Camera Locked Text in output.
If you simply want to run just use Run And Return Rc

Command are ignored after ant command in batch file

Following is the bat script code block on which i am working on:
ECHO off
IF NOT EXIST "%ANT_HOME%" (
SET ANT_HOME=%~dp0%build\apache-ant-1.8.2
SET ANT_BIN=%~dp0%build\apache-ant-1.8.2\bin
SET PATH | FIND "%ANT_HOME%;%ANT_BIN%"
)
cd "build\Run"
ant -q
cd ../..
echo "Program Terminated!"
exit
Now, my build.xml file is inside this build\Run folder so that i am first navigating to build/Run before running ant -q command (NOTE: I don't want to change this method of navigating).
The moment ant -q command is executed following things happen:
Set the environment variables as the condition.
Change directory to build\Run.
As my build.xml is inside the Run directory the ant -q command run correctly.
Ant executed correctly and not ant script terminates.
Now my current path will be build\Run ! correct <= Here i don't want this after ant is terminated, instead i want to come out from build\Run that's why i used cd../..
But the problem is I am not able to execute the commands after ant -q. This happens be the program control goes from BATCH => ANT.
Is there any way to execute my command after ant command from bat script itself ?
You may find that the ant being run is a batch file itself, in which case it simply chains to it (no return).
You should try this instead:
call ant -q
Calling a batch file (as opposed to chaining) will correctly return to the point after which you called it.

Running ant from a batch file: Later commands don't run

I have a batch file that runs ant and then copies one of the files that were produced:
ant -Dproject.version=1.1.2 release published
copy /Y D:\dir1\MyJar.jar D:\dir2\MyJar.jar
When I run the batch file, ant runs successfully, but the copy statement never happens, although it will work just fine if I type it in and hit Enter after the ant task has finished.
What is going on here?
I had the same problem once and the magic call did it.
In that batch file of yours try:
call ant -Dproject.version=1.1.2 release published
copy /Y D:\dir1\MyJar.jar D:\dir2\MyJar.jar
Cannot tell you why it worked, though. Guess it's Microsoft logic.
When you call one batch file from another (which is not always clear) you're supposed to use CALL (or call), otherwise it works more like goto and doesn't return back to the caller. Is ant actually a batch file ant.bat? This should work then:
CALL ant -Dproject.version=1.1.2 release published

Resources