Hi Brian,

Your question inspired me to figure out how to do this.  Here is what I
learned.  Disclaimer: I'm a complete nant newbie, so my way might not be
the best way.

You can log the output of your exec task and parse it with a foreach
task.  Below is an example build file that spawns an instance of cmd.exe
that executes a dir command.  If you want to test this as is, create a
file called "FATAL ERROR".  Otherwise you can try it out by replacing
the exec task with your own.  You could also put a regex task in the
foreach loop to do some sophisticated pattern matching.

Note: this build file will not work with nant versions prior to 0.85.


<project name="ACME" default="external" >
    <property name="search_string" value="FATAL ERROR" />
    <property name="logfile" value="dir.out" />
    <target name="clean" >
        <delete file="${logfile}" failonerror="false" />
    </target>
    <target name="external" depends="clean" >
        <exec 
            program="cmd.exe"
            basedir="c:\windows\system32"
            commandline="/c dir"
            output="${logfile}" >
        </exec>
        <foreach item="Line" property="log_line" in="${logfile}" >
            <fail message="Error found!"
if="${string::contains(log_line, search_string)}" />      
        </foreach>
    </target>
</project>


Good luck,
-Craig Green

-----Original Message-----
From: Dick, Brian E. [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 02, 2004 11:17 AM
To: [EMAIL PROTECTED]
Subject: [Nant-users] No exit code from exe


I'm using the exec task to run an exe, but this particular exe does not
set the exit code on success or failure. However, this exe does send a
"FATAL ERROR" message to standard output if it fails. Is there a way I
can monitor the output of this exe and set the exit code when "FATAL
ERROR" occurs? Also, I still want to see the output in the build log,
too.
Later, 
BEDick 


-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on
Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now,
one more big change to announce. We are now OSTG- Open Source Technology
Group. Come see the changes on the new OSTG site. www.ostg.com
_______________________________________________
Nant-users mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to