Check if executable command exists using ant

2019-07-03 16:10发布

Is it possible to check if a command exists as part of an ant task. For example, I want to ensure the "yasm" command is present as part of the ant task. Is this possible? If so, can you provide an example?

标签: ant
2条回答
对你真心纯属浪费
2楼-- · 2019-07-03 16:55

The best way I can think of to do this is by using the available task combined with an if in a subsequent target. If you take a look at that task page you will see that you can check to see if something exists then set a property. For example:

<available file="/path/to/my/file" type="file" property="file.present"/>

Then in the target you would say something like <target name='foo' if='file.present'>

That doesn't check for executable permissions but it will get much closer. If a task exists to check for the executable permission specifically you would still probably combine it with the if in the target.


Original answer

It is better to use the ant copy task instead of trying to execute cp yourself. This keeps its platform independent.

<copy todir"/some/target">
   <fileset dir="/some/src"/>
</copy>

More usage on the Ant documentation for the copy task.

查看更多
老娘就宠你
3楼-- · 2019-07-03 17:08

The following idiom can be used to find an executable somewhere in the environment's PATH.

  <property environment="env" /> 
  <available file="commandname"  
             filepath="${env.PATH}"  
             property="commandname.present"/>
查看更多
登录 后发表回答