Dear Bob, Thank you for your help.I generated output today,but yesterday.I don't know why...I got there was no output file exception when I exec something wrong.btw,I could use now.Thanks. Best regards, Edwin
----- 原始信件 ---- 寄件者: Bob Archer <bob.arc...@amsi.com> 收件者: netvampire.tw <netvampire...@yahoo.com.tw>; "nant-users@lists.sourceforge.net" <nant-users@lists.sourceforge.net> 寄件日期: 2011/2/11 (五) 1:52:00 AM 主 旨: RE: [NAnt-users] may I get nant exec task error message? > I want to use <exec program="aaa.bat" resultproperty="errorcode" > output="log.txt" failonerror="false">....<fail > if=${int::parse(errorcode)!=0}/> > to get errocode if exit 0 or not,if not print out what happened in > my logfile > now I use to exec aaa.bat execute fail like there is no aaa.bat > file, output > log.txt would not generate > I couldn't get build result in my email,I should go to server to > see what > happened. > I also use nant contrib trycatch,but the catch exception message is > from > <fail>custom message</fail> > I wonder to get detail message like parameters error or I use wrong > batch/execute file just like .net try catch throw exception could > throw > exception.message or like console print out > thanks I'm trying my best to understand what you are saying. If you exec something and it outputs to standard out then it should going into your log.txt. You would have to read in log.txt to get that message into a property and/or the NAnt log. Here is a simple build script: <?xml version="1.0" ?> <project name="Test1"> <property name="errormessage" value=""/> <exec program="abc.bat" output="log.txt" resultproperty="execresult" failonerror="false"/> <if test="${execresult=='1'}"> <foreach item="Line" in="log.txt" property="logline"> <property name="errormessage" value="${errormessage + logline}"/> </foreach> <echo message="The stdout was: ${errormessage}"/> <fail message="${errormessage}"/> </if> </project> Here is the bat file: echo This is sent to standard out! exit 1 When I run the script I get this output: Buildfile: file:///C:/Users/rarch/Development/Amsi-v7.0.0/Build/text.build Target framework: Microsoft .NET Framework 4.0 [exec] C:\Users\rarch\Development\Amsi-v7.0.0\Build\text.build(4,3): [exec] External Program Failed: C:\Users\rarch\Development\Amsi-v7.0.0\Build\abc.bat (return code was 1) [echo] The stdout was: C:\Users\rarch\Development\Amsi-v7.0.0\Build>echo This is sent to standard out! This to standard out!C:\Users\rarch\Development\Amsi-v7.0.0\Build>exit 1 BUILD FAILED - 1 non-fatal error(s), 0 warning(s) C:\Users\rarch\Development\Amsi-v7.0.0\Build\text.build(10,4): C:\Users\rarch\Development\Amsi-v7.0.0\Build>echo This is sent to standard out! This is sent to standard out!C:\ rch\Development\Amsi-v7.0.0\Build>exit 1 Total time: 0.1 seconds. --- Of course, you can use the contents of "errormessage" to build an email or whatever. Many programs that you exec don't actually output to standard out but they can write out a log file. I use this quite a bit to parse the log file and look for the error message so I can insert it into the nant log. Hth, BOb ------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb _______________________________________________ NAnt-users mailing list NAnt-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-users