<target name="CheckState">
<exec executable="${App.path}"/>
</target>
在此任务中,可执行文件将返回一个值,该值将指示我的应用程序的状态。我如何获得 Ant 构建文件中返回的值。我将使用此值来确定某些行为。
最佳答案
使用 resultproperty
和 failonerror
exec
的属性任务,例如:
<target name="CheckState">
<exec executable="${App.path}"
resultproperty="App.state"
failonerror="false"/>
<echo message="App state was: ${App.state}" />
</target>
引自
exec
任务文档错误和返回代码:By default the return code of an exec is ignored; when you set failonerror="true" then any return code signaling failure (OS specific) causes the build to fail. Alternatively, you can set resultproperty to the name of a property and have it assigned to the result code (barring immutability, of course).
If the attempt to start the program fails with an OS dependent error code, then halts the build unless failifexecutionfails is set to false. You can use that to run a program if it exists, but otherwise do nothing.
What do those error codes mean? Well, they are OS dependent. On Windows boxes you have to look at the documentation; error code 2 means 'no such program', which usually means it is not on the path. Any time you see such an error from any Ant task, it is usually not an Ant bug, but some configuration problem on your machine.
关于ant - 在 Ant 中,如何从 exec 获取返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4344139/