Check if executable command exists using ant

帅比萌擦擦* 提交于 2019-12-12 16:03:26

问题


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?


回答1:


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.




回答2:


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"/>


来源:https://stackoverflow.com/questions/16556746/check-if-executable-command-exists-using-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!