EXEC timeout not work with matlab application - eclipse

I have used EXEC task to open matlab in build.xml file. I have added timeout in EXEC task for terminate the task after some time. But problem is that, matlab is open and model is also building in matlab but after timeout the exec task not terminate.
<property name="BuildEngine.calc.matlabApp" value="C:\MATLAB\R2010bSP2\bin\matlab.exe"/>
<property name="modelProjectDirectory" value="${basedir}\..\${Config.ModelProject}"/>
<exec executable="${BuildEngine.calc.matlabApp}" dir="${modelProjectDirectory}" timeout="60000">
<arg value="-r"/>
<arg value="OutputResolvedParameters"/>
</exec>
after 1 min EXEC task not terminate and matlab still running.

One thing is sure: you cannot yet set up a timout on an RTC build: the Enhancement 106064 (you need a jazz account to see it) is "triaged".
Regarding the ant exec task, try adding a spawn=true attribute:
If you run Ant as a background process (like ant &) and use the <exec> task with spawn set to false, you must provide explicit input to the forked process or Ant will be suspended because it tries to read from the standard input.

Related

How to force Phing task to respect verbose exec command?

In other words how to display output of currently executed phing task?
<target name="backup_db">
<mkdir dir="${dir.sql}"/>
<exec command="mysqldump -v -h ${db.host} -u ${db.username} -p${db.password} ${db.name} > ${dir.sql}/${dump.basename}"/>
</target>
This pulls a database dump, as you see I specified -v flag to get verbose output. Command runs successfully however with no output during the dump.
Foo > backup_db:
BUILD FINISHED
Total time: 1 minute 40.81 seconds
The same command called directly in terminal will list each table one by one that's currently being dumped. How to achieve that in phing?
Adding passthru="true" to the exec solved the problem. Now I get the output in real time.

ANT_ Introducing delay between each target

I have an ant file with multiple targets (task 1 , task 2, task3..) I want to implement sleep between each target execution. I did that by introducing new target of sleep (it is Perl file execution contains sleep Perl script). Now, I called the target as:
target name="task1" description="XX" depends="sleep"
target name="task2" description="XX" depends="sleep"
When I do this, my sleep target is executed only once. It is not executing for all the targets. Please guide me to introduce sleep between each target.
The simplest way would be to execute a sleep Ant task at the start of each target:
<target name="targetX" description="xxx">
<sleep seconds="2"/>
...
</target>
You might be Suffering from Buffering. You can set $| to 1 if you need unbuffered output.
Your sleep target is executed only once -- and this is the expected behaviour in Ant to avoid duplicate execution.
You can write a BuildListener.
Put Thread.sleep(sleepTime) in targetFinished method.

How do I return a specific exit code from NANT?

I have a nant script and I see that even if my exec fails, the exit code of NANT is 0 anyway. How do I change NANT exit code?
The exec task has an attribute called "resultproperty", which is there to get the exit code.
Returning a Specific Exit Code from NANT
If the build succeeds NANT will exit with code 0, if the build fails NANT with code 1 and you can use <fail> to force this. NANT gives no other way of controlling the exit code however you could hack it:
<script language="C#">
<code>
<![CDATA[
public static void ScriptMain(Project project)
{
System.Environment.Exit(3);
}
]]>
</code>
</script>
This will end nant immediately, so perhaps you might want to create a target to be run at the very end by putting it into nant.onsuccess.
Why NANT Exit Code is 0 when <exec> Failed?
<exec> fails when the command exits with anything but 0. Normally this causes the whole build to fail in consequence and NANT to exit with code 1, with two exceptions (see 2 and 3). This gives us three possible explanations:
Your command fails but exits with 0 anyway (this is a relatively common behavior). Set the resultproperty attribute and check the property.
failonerror="False" attribute has been set on <exec> or on a higher level (<nant> or <call>). Check the NANT output to see in which order targets are being called or search for failonerror=.
The <exec> is executed as part of target started via the nant.onsuccess resp. nant.onfailure property hook. Check if and where by searching for nant.on.
To say anything more a sample NANT script or perhaps a log file would be useful.

How do I use internal commands (Command.com) from NAnt? ("type" etc)

On windows systems, certain dos commands don't have executables that can be explicitly called via NAnt's exec task. (I'm talking specifically about commands that are part of Command.com)
A complete list can be found here. While some of the more useful commands can be achieved with NAnt or NAntContrib tasks (copy, move, rename etc), some (such as 'type') cannot.
How can you execute these commands as part of a build? For example, using a wildcard, how can I easliy display the contents of a log file from an external command executed by my build (so that the external command's log file contents will become echoed into the build's log file)
Internal commands can be called using the exec task in the following manner :
<exec workingdir="${dir}" program="cmd" commandline="/c <command/> <arguments/>" />
For the scenario in the question (where the log's filename is based on the current time, partway through the build), rather than parsing/scanning for the filename, loading it into a property and then echoing it, you could echo log contents with the following task :
<exec program="cmd" workingdir="${dir}" commandline="/c type *.log" />

deploy tools: get a list of actions the tool will execute without executing the deploy script

We're in the process of evaluating MSBuild and Nant for deploys. We may roll our own tool. One thing that a different business unit -- let's call it DeptA -- would really like to have (as in it better have it) is the ability for someone in DeptA to read the script and see what it will do. Currently we do this with .bat files. We hates the bat files. Nasty nasty bat files's. But if we ask DeptA to learn a new script language (nant, msbuild) they may be resistant.
Ideally the build tool of choice would be able kick out a list of actions without doing anything else. Along the lines of:
Stop service ABC on server Z
Stop service DEF on server Z
Copy all files from
\server\dirA\dirB to \server2\dirC
Start service ABC on server Z
Start service DEF on server Z
Run all scripts in dir
\server\dirA\dirC
Is it possible to do this with MSBuild? NAnt? Without me re-learning XSL?
If I was you I would actually blend MSBuild and MSDeploy. You should have your MSBuild script perform the actions like start/stop service etc. Then let MSDeploy to the file copy. With MSDeploy you can use the -whatif switch to indicate that you only want a report of the actions to be executed instead of actually executing it. MSBuild unfortunately doesn't offer such an option out of the box you will have to "build" that into your scripts. You can do this with properties and conditions. For example it might look something like this:
<Project ...>
<PropertyGroup>
<!--
Create the property to use, and declare a default value.
Here I've defaulted this to true because it is better to force the
caller to explicitly specify when to perform the action instead of it
being the default.
-->
<SimulateExecution Condition= '$(SimulateExecution)'==''>true</SimulateExecution>
</PropertyGroup>
<Target Name="Deploy">
<Message Text="Deploy started" />
<Message Text="Stop service ABC on server Z"/>
<WindowsService ... Condition=" '$(SimulateExecution)'=='false' "/>
<Message Text="Stop service DEF on server Z"/>
<WindowsService ... Condition=" '$(SimulateExecution)'=='false' "/>
<!-- Call MSDeploy with the Exec task. -->
<PropertyGroup>
<MSDeployCommand>...\msdeploy.exe YOUR_OPTIONS_HERE</MSDeployCommand>
<!-- Append the -whatif to the command if this is just a simulation -->
<MSDeployCommand Condition= '$(SimulateExecution)'=='false' ">$(MSDeployCommand) -whatif</MSDeployCommand>
</PropertyGroup>
<Exec Command="$(MSDeployCommand)" />
... More things here
</Target>
</Project>
For the service actions you can use the WindowsService task from the MSBuild Extension Pack. You will have to fill in the blanks there.
When you call MSDeploy you should just use the Exec task to invoke msdeploy.exe with your parameters. If you pass the -whatif it will not actually perform the actions, just report what it would have done. These will be logged to the msbuild log. So if you invoke msbuild.exe with /fl you will get those actions written out to a file. The only issue that I've seen when taking this approach is that for msdeploy.exe you many times have to use full paths (those without ..) which can sometimes be tricky so be wary of such paths.