ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rhino" <rhi...@sympatico.ca>
Subject Re: Exec task in Ant 1.6.1
Date Wed, 14 Apr 2004 23:20:50 GMT

----- Original Message ----- 
From: "Matt Benson" <gudnabrsam@yahoo.com>
To: "Ant Users List" <user@ant.apache.org>
Sent: Wednesday, April 14, 2004 1:20 PM
Subject: Re: Exec task in Ant 1.6.1


> --- Rhino <rhino1@sympatico.ca> wrote:
> > That was definitely an intriguing idea but it didn't
> > work. It launched a DB2
> > command window but didn't execute either of the
> > commands in the inputstring.
> > I checked the comment on the procedure afterwards
> > and it hadn't changed to
> > the new value. I tried adding an
> > output="db2cmd3.txt" but nothing at all was
> > written to it.
> >
> > > You could also use a real line in the buildfile to
> > > signify the line break in the inputstring
> > attribute,
> > > OR put the whole thing as two lines in a file and
> > use
> > > that on the input attribute.  I'd try this general
> > > approach first; you may get lucky.
> >
> > Could you clarify both of these approaches please? I
> > don't have a clear idea
> > of what you mean by either one.
> >
>
> Here I meant the general approach of sending input to
> the executable.  The other things were different ways
> of specifying the input source (input vs. inputstring)
> and breaking the two commands, e.g.
> "foo${line.separator}bar${line.separator}" vs. "foo
> bar
> " (I only now realized that with this approach you'd
> probably still need an ending line break).  But it
> seems that this isn't working....
>
> However, it just so happens I have an installation of
> db2 on my Win2K box so I have been playing around with
> it.  Are you sure you need db2cmd?  It doesn't seem to
> do a whole hell of a lot, other than spawning off some
> windows and generally making it hard to do anything
> automated.

Actually, db2cmd is fairly crucial to the whole process; it sets up db2
environment variables and so forth. You can read about it in the Command
Reference in Chapter 1, System Commands assuming you've got a reasonably
current version of DB2 (which means probably anywhere from Version 5 to
Version 8, the current version).

> Try the approach above using the db2
> executable, so that db2 is treated as an interactive
> executable.  You may be pleasantly surprised.
>
> For example, I created a file db2input that contained
> the text:
>
> list active databases
> quit
>
> and from a plain CMD window I entered:
>
> db2 <db2input
>
> This seemed to work and can be mimicked this way:
>
> <exec executable="db2" input="db2input" />
>
I'm afraid that approach only works for commands that don't need a DB2
connection, like 'list active databases' or 'quit'. I figured out how to do
that much last night, although my approach was different:
<exec executable="cmd.exe" os="Windows XP">

    <arg value="/c db2cmd db2 get dbm cfg"/>

</exec>

The good news is that I finally got something I can live with, after futzing
around for a while. For the sake of anyone else who is following this
thread, now or in the future, I found that this works fine:

---
<exec executable="cmd.exe" os="Windows XP">

<arg value="/c db2cmd db2 -tvf db2_001.in -z db2_001.out"/>

</exec>

---

where file db2_001.in contains:

---

connect to sample;

comment on table employee is 'ZZZ';

quit;

---

For what it's worth, I initially tried doing this:

---
<exec executable="cmd.exe" os="Windows XP" output="db2_001.out">

    <arg value="/c db2cmd db2 -tvf db2_001.in/>

</exec>

---

but found that it didn't write anything to the output file. Therefore, I
used the -z switch on the db2 command to tell it to write the output to file
db2_001.out. That worked fine, except that you have to remember to delete
db2_001.out before each use, otherwise it just keeps appending to the file.
The -o switch could have been used as well but would only have written the
output from the commands; I prefer to get the input *and* output in the
output file so that I can verify that both were what I expected.

> Although personally I avoid external files like the
> plague and would probably use the ${line.separator}
> property to delimit lines in the inputstring
> attribute.
>
I would still prefer to supply my commands inline rather than pass them in
through a file but I haven't figured out how to do that yet. If anyone knows
how I can do that with my DB2 situation, I'd love to hear it....

> Now that we have degenerated this into a db2
> discussion instead of an Ant discussion... ;)
>
Nothing wrong with learning something new ;-) Besides, the question was
primarily about Ant so I don't feel that we went too far off-topic.

Thanks to you, Matt, for the time you took to help and thanks also to Luis
whose example of executing a batch file will get used for non-DB2 stuff in
the near future.

Rhino


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


Mime
View raw message