You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Buck, Robert" <rb...@verisign.com> on 2008/01/17 16:20:29 UTC

using to check for tool availability

Hello,
 
I have a problem I am trying to solve that I need some help with. What
I'd like to do is check for the availability of an executable tool on
the system path. If the tool is available, then allow extra (secret
sauce) features to be enabled. Otherwise the extra (non-essential) build
features are disabled.
 
My thought was to use exec to determine if the tool exists. If someone
has a better way, please let me know.
 
So below you will see an attempt to use exec, and if it fails, set a
property, and check for that property down stream. Unfortunately I get
very bizzare results.
 
 
FIRST ISSUE
First, the state of the errorproperty makes no sense to me. Given the
following example, when dot is not available, the script says it is. I
would have thought that if there were an error, it would always be set.
Therefore other tasks should use the "unless" syntax. But the opposite
is true. This seems inconsistent with how the rest of Ant works. Try
this fragment out!
 
  <target name="check-for-dot">
    <exec executable="dot" failonerror="false"
failifexecutionfails="false" errorproperty="dot.is.available">
      <arg value="-help"/>
    </exec>
  </target>

  <target name="do-dot" depends="check-for-dot"
unless="dot.is.available">
    <echo message="dot is available"/>
  </target> 
 
> ant -f make-dot.xml
Buildfile: make-dot.xml
 
check-for-dot:
     [exec] Execute failed: java.io.IOException: CreateProcess: dot
-help error=2
 
do-dot:
     [echo] dot is available
 
This result makes no sense.
 
 
SECOND ISSUE
Second, notice that nasty little "Execute failed" stuff? I want to
supress it, but no matter what property I set in the exec task, the
output (or something similar) still comes screaming through. I know exec
may fail, I am doing this on purpose. So I want to tell ant to shut up
in this one case only. I would have thought that using the output and
error properties would help; they did not.
 
Does anyone have any better suggestions for how to check for tool
existence in Ant?
 
Bob

RE: using to check for tool availability

Posted by "Buck, Robert" <rb...@verisign.com>.
The <available task worked. Thanks. 

-----Original Message-----
From: Dominique Devienne [mailto:ddevienne@gmail.com] 
Sent: Thursday, January 17, 2008 10:49 AM
To: Ant Users List
Subject: Re: using <exec> to check for tool availability

On Jan 17, 2008 9:20 AM, Buck, Robert <rb...@verisign.com> wrote:
> Does anyone have any better suggestions for how to check for tool 
> existence in Ant?

<property environment="env" />
<available file="dot" filepath="${env.PATH}" ... />

But you need to know the exact file name (dot or dot.exe), and env.PATH
is not always portable because of case on Windows, where it can be Path,
path, or PATH or else. Your <exec> approach is more reliable, but more
verbose. Maybe a <redirector> in exec would help, and a "grep" of know
output from the command to see if it works or not. Just suggestions to
explore. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: using to check for tool availability

Posted by Dominique Devienne <dd...@gmail.com>.
On Jan 17, 2008 9:20 AM, Buck, Robert <rb...@verisign.com> wrote:
> Does anyone have any better suggestions for how to check for tool
> existence in Ant?

<property environment="env" />
<available file="dot" filepath="${env.PATH}" ... />

But you need to know the exact file name (dot or dot.exe), and
env.PATH is not always portable because of case on Windows, where it
can be Path, path, or PATH or else. Your <exec> approach is more
reliable, but more verbose. Maybe a <redirector> in exec would help,
and a "grep" of know output from the command to see if it works or
not. Just suggestions to explore. --DD

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org