I'm facing a problem using Ant
I'd like to check for the end of a long process, without using a nasty <sleep> command.
In my Ant target, I'm launching
<exec executable="my long process" />
When I'm manually checking for the end of the process, I'm using this following command :
watch " "check ksh script" | grep "ONLINE" "
When the grep returns something, it means my process has ended (because the check ksh script outputs ONLINE)
How can I perform the same check in Ant ?
I'm trying to use something like the following (to simulate the watch command)
<exec executable="my long process" />
<waitfor maxwait="2" maxwaitunit="minute" checkevery="5" checkeveryunit="second">
// do something here to check "ONLINE"
</waitfor>
But I don't know what to put in the <waitfor>
There are ways with Ant to execute your check script and then test its output, but it cannot fit the waitfor tasks which is accepting just one condition.
You could try with scripting though.
See: http://ant.apache.org/manual/Tasks/conditions.html#scriptcondition
It should look something like that:
<scriptcondition language="javascript" value="true">
var p = java.lang.Runtime.getRuntime().exec("ksh check");
p.waitFor();
var reader = new java.io.InputStreamReader(p.getInputStream());
var out = org.apache.tools.ant.util.FileUtils.safeReadFully(reader);
self.setValue(out.contains("ONLINE"));
</scriptcondition>
Related
Visual Build Professional (Pro, vbp) has "Success Exit Codes" where I can put in a whitelisted values...(when I define a call out to an external .exe)
When I create a call to an external .exe , how can I capture the return-code / exit-code and put it into a macro?
Basically, I'm trying to do in Visual Build Pro, what the below msbuild does.
Namely, capture the value of "ExitCode" to a property (macro in vbp language)...called MyExitErrorCode
<Target Name="ExecuteSomeEXETarget">
<Exec Command='"C:\Some.exe"' ContinueOnError='true'>
<Output TaskParameter="ExitCode" PropertyName="MyExitErrorCode"/>
</Exec>
<Message Text="The exit code is $(MyExitErrorCode)"/>
<Error Text="Error while executing Some EXE" Condition="'$(MyExitErrorCode)' > '0'" />
</Target>
You can do a "Run Program"
In the "Command" put the path to your exe.
On the "More" tab, select the "Continue building" radio button.
..
Then you can capture the macro %RUNPROGRAM_EXITCODE%
..
For example, after your "Run Program" (step), Create a "Log Message" (step), and put this in
Hello '%RUNPROGRAM_EXITCODE%' !
.......
Not sure why the Macro doesn't show up in the list of global macros.
Now that I know the magic macro name, the documentation can be found
http://www.kinook.com/VisBuildPro/Manual/index.htm?visualbuild5_x.htm
• The build status of the Run Program action will always be a value from BuildStatusEnum and not the exit code of the process. The exit code is available in the RUNPROGRAM_EXITCODE temporary macro.
http://www.kinook.com/VisBuildPro/Manual/index.htm?runprogramaction.htm
The Run Program action creates a step to launch any external application, program, batch file, or command script. Visual Build starts and monitors the application, captures any output and logs it to the Output pane (and a log file if enabled), and terminates the application if the build is stopped.
When the step completes, the following temporary macros are created or updated:
RUNPROGRAM_EXITCODE: If the Wait option is checked, the exit code of the process will be stored in this macro.
RUNPROGRAM_PROCESSID: If the Wait option is unchecked, the process ID of the launched process will be stored in this macro.
For some specific purpose, I need to install some fonts on the instances. It comes as no surprise when I choose StartUp Task to accomplish that goal. I've configured the Service Definitions as below:
<Startup>
<Task commandLine="Fonts\InstallFonts.vbs" executionContext="elevated" taskType="simple" />
</Startup>
Nothing special here. Click and run, it failed. However, if I changed the commandLine into a cmd file including just nonsense, namely "echo test", the instance would run without ado. So there must be some issue with my scripting:
Const FONTS = &H14&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(CreateObject("Scripting.FileSystemObject").GetAbsolutePathName("."))
Set fontFolder = objShell.Namespace(FONTS)
Set rxTTF = New RegExp
rxTTF.IgnoreCase = True
rxTTF.Pattern = "\.ttf$"
Set fso = CreateObject("Scripting.FileSystemObject")
FOR EACH FontFile IN objFolder.Items()
IF rxTTF.Test(FontFile.Path) THEN
IF NOT fso.FileExists(fontFolder.Self.Path+"\\"+FontFile.Name) THEN
FontFile.InvokeVerb("Install")
END IF
END IF
NEXT
The script should come with no error because I've tested it either locally or on Azure via RDP.
Weirdly, when I put it in the startup, the role just won't start. The instance just keeps recycling and at last says "I'm unhealthy". Even if I deprecate the vbs into just one line of code - the first line Const FONTS = &H14&, it just won't start. Even if I wrap the invocation of the vbs into a cmd file, namely to put something like "cscript /B file.vbs", it won't run either.
So I'm concluding that there must be some issue regarding the communication between the script and the Windows Azure monitor. I'm not sure but I think the monitor might take the running script as a failed task. Besides, I'm wondering if there is any timeout for the startup task, which should be the problem though, because the script can guarantee that no UI interaction block the process.
Any idea would be greatly appreciated.
I am sure you must have but just for the sake of confirmation, have you checked that the InstallFonts.vbs file is exported with the package? I mean is the "Copy To Output Directory" is set to "Copy Always/Copy if newer"?
This is pretty much possible that it is not able to locate your file.
You need to write a cmd file as a start up task. In your cmd file, you can call the vbs file using the command line tool cscript.
Azure start up can compile only command line tools.
Oh god, I finally solved the problem.
Although the compiler does quite a good job usually, it allows to use subfolder as a source of command, I mean something like "Subfolder\command.cmd", which will not work always. I've seen examples in which people put whatever we do in cmd in commandLine property, such as "copy fileA fileB" and it really works. But as for vbs, you need to be cautious. Until now I still don't know what's under the cover, but there should be some problem with the path. And the solution is definitely simple, instead of doing the subfolder work for tidiness, just leave the command file in the root folder like most people do:
<Startup>
<Task commandLine="InstallFonts.vbs" executionContext="elevated" taskType="simple" />
</Startup>
And thank you all the same, Kunal. :)
My first question. Please bear with me!
I have an Ant task that need to get some input from the user before proceeding. I use the Input task to achieve this. The input message will contain Swedish characters (eg å, ä and ö) but I am unable to get Ant to output the message properly. I'm testing this using the command line on a machine running Windows 7 Pro English (but obviously using a Swedish keyboard). Example:
<input message="åäö"/>
will output:
[input] Õõ÷
The build.xml is saved in UTF-8 format. If I do 'chcp' on the command line I get "Active code page: 850".
The same result can be seen when doing an echo:
<echo message="åäö"/>
will output:
[echo] Õõ÷
But in the case of the echo task I'm able to do:
<echo encoding="850" message=åäö">
to get the expected output:
[echo] åäö
The input task does however not have an encoding attribute and I'd very much prefer to not have to define an encoding at all, especially not on a per-task level (since I can't tell for sure on what machine the Ant script will be run from).
PS I have additional problems with the received input if it contains åäö and I set the input as a property that is later used in a filter copy task, but I guess that's a whole other question
I can observe the issue on my Polish Windows.
<script language="javascript">
java.lang.System.out.println("default charset: "
+ java.nio.charset.Charset.defaultCharset());
</script>
reports default charset as "windows-1250" while the console operates at "iso-8859-2" (I guess so).
Looks like <input> task uses the default charset thinking it would match the console input. In case it does not, I managed to override the encoding this way:
set ANT_OPTS=-Dfile.encoding=iso-8859-2
ant
In your case I would try to force 850, as it looks like JRE defaults to something else.
This question helped me to find the property name.
It is also important where ant is run from. If I run it from my ide, jedit console plugin, I don't need to override encoding, because I configured it to operate in windows-1250. So it seems to be another workaround, using an IDE.
I'm try to develop a cruise control step which will process database migration scripts and apply them.
I'd like to be able to get hold of a list of the modifications from the SourceControl (to see if any new database changes need to be applied).
Any ideas how I can achieve this? I know that this information is written into the log xml but I was wondering if there is an easy mechanism to get a reference to this from with an Ant builder.
I have investigated writing a custom CC Listener or Builder plugin but neither supply this in the interface.
We have "svn update" as one of the steps in ant builder, and later we use output redirected to the file (ant property also could be used):
<exec executable="svn" dir=".">
<arg line="up"/>
<redirector output="svnup.log" alwayslog="true" append="true"/>
</exec>
<property name="svnup.log" value="svnup.log"/>
this creates file named "svnup.log" in the build folder with output of "svn up" command.
I think I'm going to try to write a custom plugin implementing Publisher
#Override
public void publish(Element cruisecontrolLog) throws CruiseControlException { XMLLogHelper xmlHelper = new XMLLogHelper(cruisecontrolLog);
Set<Modification> modifications = xmlHelper.getModifications();
for (Modification modification : modifications) {
handleModification(modification);
}
}
Or another idea is to use the timestamp flag in the sscm ant task combined with the cclastbuildtimestamp property supplied to the ant builder to produce a list of files changed since last build.
In my ant script, i have to execute this Read.exe
Read.exe will browse through version control and output a text file and which takes about a minute to complete. This text file is loaded as a .properties file for the antscript. However, it seems to me that i am unable to finish this task in time. By the time this .properties file completes, i have already executed another task which required some properties from this file. Therefore my question is.. how can i add delay in ANT script?
<sleep milliseconds="10"/>
http://ant.apache.org/manual/Tasks/sleep.html
There is a sleep task: <sleep milliseconds="10"/>
Edit
You might also use waitfor task, as described here.