在Ant中,如何抑制exec错误;CreateProcess错误=2";?

在Ant中,如何抑制exec错误;CreateProcess错误=2";?,ant,exec,Ant,Exec,我正在尝试执行一个程序,如果失败,我有一个回退方法来获取所需的信息。并非每个使用此构建脚本的人都会安装该程序。我的任务如下: <exec executable="runMe" failonerror="false" failifexecutionfails="false" outputproperty="my.answer" errorproperty="my.error" error="myerror.txt" />

我正在尝试执行一个程序,如果失败,我有一个回退方法来获取所需的信息。并非每个使用此构建脚本的人都会安装该程序。我的任务如下:

<exec executable="runMe"
      failonerror="false"
      failifexecutionfails="false"
      outputproperty="my.answer"
      errorproperty="my.error"
      error="myerror.txt" />

显然,我误解了Ant手册,因为我认为通过设置error或errorproperty,错误将被重定向,而不会显示在屏幕上

是否可以隐藏消息“executefailed:java.io.IOException:cannotrunprogram“runMe”

或者,是否有方法确定该程序是否可以在不检查其存在的情况下运行?如果程序在用户的系统上,则不同用户之间的程序将不在同一位置

谢谢,


Paul

试试ant contrib的Try/catch/finally命令


尝试ant contrib的Try/catch/finally命令


这样做的目的是在Ant中为我的项目获得Subversion版本。一些开发人员安装了命令行Subversion,而其他人没有,因此我需要一种方法来测试svnversion的存在

最后,我使用了一个批处理文件来测试命令:

REM File checkCommand.bat
@echo off
%1 >NUL 2 >NUL
if errorlevel 1 goto fail

REM command succeeded 
exit 0

:fail
REM command failed
exit 1
在我的Ant target中,我这样运行:

<target name="checkForSvnversion">
  <local name="cmdresult" />
  <exec dir="." executable="com"
        resultproperty="cmdresult"
        failonerror="false"
        failifexecutionfails="false">
      <arg line="/c checkCommand.bat svnversion" />
  </exec>

  <condition property="exec.failed">
    <equals arg1="${cmdresult}" arg2="1" trim="true" />
  </condition>
</target>

我有两个目标取决于这一结果:

<target name="getRevisionFromSvnversion" depends="checkForSvnversion"
        unless="exec.failed">
  etc etc
</target>

等等


等等
最后,我调用以获取修订的任务是:

<target name="getRevision"
        depends="getRevisionFromSvnversion,getRevisionFromEntries">
  <echo>My rev is ${svn.revision}</echo>
</target>

我的版本是${svn.revision}

这样做的目的是在Ant中为我的项目获得Subversion版本。一些开发人员安装了命令行Subversion,而其他人没有,因此我需要一种方法来测试svnversion的存在

最后,我使用了一个批处理文件来测试命令:

REM File checkCommand.bat
@echo off
%1 >NUL 2 >NUL
if errorlevel 1 goto fail

REM command succeeded 
exit 0

:fail
REM command failed
exit 1
在我的Ant target中,我这样运行:

<target name="checkForSvnversion">
  <local name="cmdresult" />
  <exec dir="." executable="com"
        resultproperty="cmdresult"
        failonerror="false"
        failifexecutionfails="false">
      <arg line="/c checkCommand.bat svnversion" />
  </exec>

  <condition property="exec.failed">
    <equals arg1="${cmdresult}" arg2="1" trim="true" />
  </condition>
</target>

我有两个目标取决于这一结果:

<target name="getRevisionFromSvnversion" depends="checkForSvnversion"
        unless="exec.failed">
  etc etc
</target>

等等


等等
最后,我调用以获取修订的任务是:

<target name="getRevision"
        depends="getRevisionFromSvnversion,getRevisionFromEntries">
  <echo>My rev is ${svn.revision}</echo>
</target>

我的版本是${svn.revision}

我不知道这件事。虽然我现在有一个问题的解决方案(作为答案发布),但一旦我们完成这个版本,我会尝试一下。我想删除我正在使用的批处理文件。我不知道。虽然我现在有一个问题的解决方案(作为答案发布),但一旦我们完成这个版本,我会尝试一下。我想删除我正在使用的批处理文件。