# ant-user mailing list archives

##### Site index · List index
Message view
Top
From Matt Benson <gudnabr...@yahoo.com>
Subject Re: How to hide output of an <exec> -- what about <presetdef>
Date Fri, 15 Apr 2005 20:38:51 GMT
```--- Ninju Bohra <ninju_bohra@yahoo.com> wrote:

> While waiting for a <redirector> fix (which will
> neccesiate a move to 1.6.3) I wonder if I can use
> <presetdef> to solve my problem (though maybe not as
> elegently).

Elegant enough.
>
> Define a presetdef for each <exec> for the standard
> (console output) invocation.  Inside the main script
> use a simple <if> check on the presence of an
> \${output.file} property and use that (instead of
> calling the <exec> task directly), i.e.:
>
>   <if>
>      <isset property="output.file"/>
>      <then>
>          <imp.exe.predef output=\${outputfile}/>
>      </then>
>      <else>
>          <imp.exe.predef/>
>      </else>
>   </if>
>
> Am I using the <presetdef> correctly?

Not that I can tell.  In pure Ant:

<target name="foo" depends="file,nofile">
<myexec executable="whatever" />
</target>

<target name="file" if="output.file">
<presetdef name="exec">
<exec output="\${output.file}"
</presetdef>
</target>

<target name="nofile" unless="output.file">
<presetdef name="exec">
<exec />
</presetdef>
</target>

HTH,
Matt

>
> --- Ninju Bohra <ninju_bohra@yahoo.com> wrote:
>
> > Can you give a further detail on how to use the
> > <redirector> solution (having never used
> > <redirector>s
> > before)?
> >
> > I am using ANT 1.6.2 (can't use 1.6.3beta1 :-()
> >
> > Taking Ivan Ivanov's advice I would like to have
> the
> > output from the <exec> either come to the screen
> > (when
> > run by user) or go to file (when invoked by CC)
> > based
> > upon a presence of a property...
> >
> > --- Matt Benson <gudnabrsam@yahoo.com> wrote:
> >
> > > I guess spawn could work.  A couple more
> options:
> > > You want to have a single task declaration that
> > uses
> > > options.  Meaning you can't just declare file
> > > without
> > > using it all the time.  So you have two choices,
> > > still
> > > using I/O redirection.  With Ant 1.6.3 you will
> > have
> > > the alwayslog attribute on a redirector, so you
> > > could
> > > use <redirector output="NUL"
> alwayslog="\${dolog}"
> > > />.
> > > Or you could use conditions to store a
> redirector
> > to
> > > a
> > > particular ID.  So your exec would always use
> > > <redirector refid="r" /> which might ref
> > > <redirector id="r" /><!-- default behavior -->
> > > or
> > > <redirector id="r" output="NUL" />
> > >
> > > HTH,
> > > Matt
> > >
> > > --- Ninju Bohra <ninju_bohra@yahoo.com> wrote:
> > >
> > > > I thought about using the output attribute,
> but
> > > what
> > > > value would I use for when they DO want the
> > output
> > > > to
> > > > come to the console?  I don't want to have the
> > > > <exec>
> > > > task duplicated (differing only in one have
> the
> > > > output="NUL" and the other not using the
> output
> > > > attribute) and then a set of conditions
> > > controlling
> > > > which <exec> to invoke.
> > > >
> > > > Actually, I am thinking of using the spawn
> > > attribute
> > > > instead.  The default value of the
> > \${hide_output}
> > > > property would be 'false', the CC script would
> > set
> > > > the
> > > > \${hide_output} to 'true' when it invoke the
> > script
> > > > and
> > > > the single task call would be:
> > > >
> > > >    <exec executable="..."
> spawn=\${hide_output}>
> > > >         <arg line...>
> > > >             .
> > > >             .
> > > >             .
> > > >    </exec>
> > > >
> > > > What do you think?
> > > > --- Matt Benson <gudnabrsam@yahoo.com> wrote:
> > > > > If you are using a recent version of Ant,
> you
> > > > could
> > > > > redirect to your null device (a file).
> Since
> > > > you're
> > > > > on Windows (I assume from the backslashed
> > > paths),
> > > > > the
> > > > > file will be NUL .  You could do some
> > > conditional
> > > > > stuff based on OS to choose NUL or /dev/null
> > as
> > > > your
> > > > > null device and be cross-platform, but
> > basically
> > > > > <exec
> > > > > output="NUL"> should work on Windows.
> > > > >
> > > > > HTH,
> > > > > Matt
> > > > >
> > > > > --- Ninju Bohra <ninju_bohra@yahoo.com>
> wrote:
> > > > > > Hello all,
> > > > > >
> > > > > > On my Windows Box, I have a series of
> <exec>
> > > > calls
> > > > > > to
> > > > > > do a set of Orcale database operations,
> one
> > of
> > > > the
> > > > > > calls look like:
> > > > > >
> > > > > >        <exec executable="imp.exe">
> > > > > >           <arg value="\${import.login}"/>
> > > > > >           <arg
> > > > > >
> value="file=\${export.dir}\DataExport.dmp"/>
> > > > > >           <arg
> > > > > > value="log=\${export.dir}\DataImport.log"/>
> > > > > >           <arg
> > > > > >
> value="parfile=\${export.dir}\fromuser.txt"/>
> > > > > >           <arg
> > value="touser=\${import.user}"/>
> > > > > >           <arg value="BUFFER=32000000"/>
> > > > > >           <arg
> value="RECORDLENGTH=65535"/>
> > > > > >           <arg value="IGNORE=N"/>
> > > > > >           <arg value="GRANTS=N"/>
> > > > > >           <arg value="ROWS=Y"/>
> > > > > >           <arg value="COMMIT=N"/>
> > > > > >           <arg value="INDEXES=Y"/>
> > > > > >           <env key="NLS_LANG"
> > > > > > value="AMERICAN_AMERICA.UTF8"/>
> > > > > >        </exec>
> > > > > >
> > > > > > Now everything works fine with the program
> > > > > > generating
> > > > > > a lot of output to the console.  This
> output
> > > is
> > > > > > useful
> > > > > > when the call initiated by a user, but we
> > also
> > > > > have
> > > > > > an
> > > > > > automated CruiseControl process that uses
> > the
> > > > same
> > > > > > targets to load it's database and the
> > problem
> > > is
> > > > > > that
> > > > > > all that output (2k+ lines) ends up
> > cluttering
> > > > the
> > > > > > final CC email that gets generated.
> > > > > >
> > > > > > So is there any simple parameter that I
> can
> > > send
> > > > > to
> > > > > > the <exec> task to tell it to suppress
> > sending
> > > > the
> > > > > > output the to System.out?
> > > > > >
>
=== message truncated ===

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org