You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Oisin Kim <oi...@aurium.net> on 2002/04/17 11:32:41 UTC

Run time commands

Hi All,
I've googled to no avail and still can't find a solution to this
problem, I need to give runtime inputs to programs run using targets
which contain the "java" command. 
I know I can pass inputs using an argument <arg value="xxx"/> but I need
to input data base on the output from the program I'm running!
Thanks for any help in advance!
Oisin


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Run time commands - a Solution

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 17 Apr 2002, Oisin Kim <oi...@aurium.net> wrote:

>       <arg value="some.properties"/> 	<!--a paramter, a properties file-->
>       <arg value="somefilename.txt"/>	<!--a paramter, some file name-->

> Since this java command no longer uses the option "fork=true" you
> can't define a Path to run java from, everything is run relative to
> the folder the Ant build script is contained (if you run Ant from
> the command line) in or if you're using something like netbeans,
> relative to the netbeans bin directory, although this may be just a
> config issue!

Use

   <arg file="some.properties"/> 	<!--a paramter, a properties file-->
   <arg file="somefilename.txt"/>	<!--a paramter, some file name-->

instead

Ant will pass the absolute pathname of the files on the command line
and assume that relative paths are relative to your project's basedir.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Run time commands - a Solution

Posted by Oisin Kim <oi...@aurium.net>.
Hi All,

Ok thanks, that's much clearer now, my only apology is that I didn't
make myself clearer from the first email, I was clearly asking the wrong
question!

Just for the benefit of anyone who will need to do something like this
again. 
Here's a sample target which will allow user input from System.in or the
running Java application:

<target name="run-with-user-input" depends="build-classes">
<!--build-classes will simply build the classes used by this task-->
    <java classname="org.apache.SomeClassName" >      
      <classpath refid="some.classpath"/> <!--the classpath-->
      <arg value="some.properties"/> 	<!--a paramter, a properties
file-->
      <arg value="somefilename.txt"/>	<!--a paramter, some file
name-->
      <arg value="-mnop"/>			<!--a paramter, passing
options in-->
    </java>
</target>

Since this java command no longer uses the option "fork=true" you can't
define a Path to run java from, everything is run relative to the folder
the Ant build script is contained (if you run Ant from the command line)
in or if you're using something like netbeans, relative to the netbeans
bin directory, although this may be just a config issue! (sorry for the
OT ness of that!)

Hope this helps someone!

Much thanks go to Stefan and Kevin!

Oisin
--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Run time commands

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 17 Apr 2002, Oisin Kim <oi...@aurium.net> wrote:

> I also run a java class that starts (through JNI) a native C++ / MFC
> application, this too cannot take in any inputs from users which
> seems similar to the System.in problem,

It is the same problem, yes.

> but surely we should be able to give inputs to a running Java
> program, or am I missing the point of the exec and java commands in
> Ant (which I probably am ;-p)

It is a known limitation for <exec> and <java fork="true">, non-forked
<java> tasks should be able to read from System.in.  There is no
workaround, sorry.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Run time commands

Posted by Oisin Kim <oi...@aurium.net>.
Hi Stefan,

Thanks again for your response, if only commercial software had this
sort of support, we'd all be much happier!

I wanted to do inputs using System.in, or from a running class. I was
making an example of taking System.in inputs (which I now know I can't
do!).  I also run a java class that starts (through JNI) a native C++ /
MFC application, this too cannot take in any inputs from users which
seems similar to the System.in problem, but surely we should be able to
give inputs to a running Java program, or am I missing the point of the
exec and java commands in Ant (which I probably am ;-p)
The MFC app runs as a Windows system tray tool, so a little icon appears
in the task bar in windows, which you click to provide inputs. This is
completely unresponsive when run from Ant. It's as if any user input is
banned when using Ant exec or java commands to the resultant running
item (in this case the MFC app).

At the moment I'm using scripts to run the class, which is not very nice
since we've moved all our development over to Ant (from makefile)
without any other problems, we all love it, it has saved us ages in
build times!

So really what I need to know is : 
Is user input not possible when running exec or java commands from Ant?

Thanks again for your help, you have improved even more my views on Ant!

Oisin



-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org] 
Sent: 17 April 2002 13:22
To: ant-user@jakarta.apache.org
Subject: Re: Run time commands


On Wed, 17 Apr 2002, Oisin Kim <oi...@aurium.net> wrote:

> I've tried using the exec aommand but the result is exactly the
> same.

Either I don't understand what you want or you didn't understand my
answer - probably both ;-)

> Commandline input is not possible.

What exactly do you mean with command line input?

Reading from System.in?  This is in fact not supported by Ant -
neither for <exec> nor for forked <java> tasks.

Passing parameters on the command line?  This works.

I thought you had an executable that created some output and you want
to use that (the output) as a command line parameter.  Something like

mv `basename $i .bak` $i

which would remove the .bak suffix from $i on a Unix command line.
This can be done with the help of <exec>'s outputproperty attribute.

Stefan

--


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Run time commands

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 17 Apr 2002, Oisin Kim <oi...@aurium.net> wrote:

> I've tried using the exec aommand but the result is exactly the
> same.

Either I don't understand what you want or you didn't understand my
answer - probably both ;-)

> Commandline input is not possible.

What exactly do you mean with command line input?

Reading from System.in?  This is in fact not supported by Ant -
neither for <exec> nor for forked <java> tasks.

Passing parameters on the command line?  This works.

I thought you had an executable that created some output and you want
to use that (the output) as a command line parameter.  Something like

mv `basename $i .bak` $i

which would remove the .bak suffix from $i on a Unix command line.
This can be done with the help of <exec>'s outputproperty attribute.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Run time commands

Posted by Oisin Kim <oi...@aurium.net>.
Hi again,
I've tried using the exec aommand but the result is exactly the same.
Commandline input is not possible.
Any ideas are welcome!

Oisin

Heres the new test task:
<target name="test" depends="module-test">
    <exec dir="${ant.project.name}" executable="java">
        <env key="PATH" path="${aurium.classpath}"/>
        <arg value="net.aurium.harness.Harness"/>
        <arg value="aurium.properties"/>
        <arg value="tests.txt"/>
        <arg value="-m"/>
    </exec>
</target>

I've also tried:

<target name="test" depends="module-test">
    <exec dir="${ant.project.name}" executable="java.exe" os="Windows
2000">
        <env key="PATH" path="${aurium.classpath}"/>
        <arg value="net.aurium.harness.Harness"/>
        <arg value="aurium.properties"/>
        <arg value="tests.txt"/>
        <arg value="-m"/>
    </exec>
</target>

-----Original Message-----
From: Oisin Kim [mailto:oisin.kim@aurium.net] 
Sent: 17 April 2002 12:29
To: 'Ant Users List'
Subject: RE: Run time commands


Hi Stefan,

Thanks for the reply, 

I'm using the <java..../> tag to call run a class which then reads reads
some properties files and runs some other java classe(s) using
reflection, not the exec command.  I have seen the <exec> command but
thought it wasn't as clean a solution as using <java>.

The excerpt from the ant XML file is:

<target name="test" depends="module-test">
    <java classname="net.aurium.harness.Harness"
dir="${ant.project.name}" fork="true">      
        <classpath refid="aurium.classpath"/>
        <arg value="aurium.properties"/>
        <arg value="tests.txt"/>
        <arg value="-m"/>
    </java>
</target>

The module-test simply builds the classes the net.aurium.Harness will
run using reflection.

As I mentioned to Kevin off-list, the command line question is actually
a simplification of the real problem, but I'd hope I wan't too wrong
when I made the simplification, as I think they're related.  The thing I
didn't mention is that I'm also using JNI to receive native Event calls
from a MFC/C++ application, the MFC application is frozen as I start it
from one of the relfected classes and it seems that Ant won't allow me
to use runtime data input to the running application from commandline or
from this MFC app.

Apologies if I've misled you with my original question, I was hoping
someone would know a solution to the simpler version I gave first and I
could work the rest out myself!

Thanks again for the reply,

Oisin



-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org] 
Sent: 17 April 2002 10:52
To: ant-user@jakarta.apache.org
Subject: Re: Run time commands


On Wed, 17 Apr 2002, Oisin Kim <oi...@aurium.net> wrote:

> I know I can pass inputs using an argument <arg value="xxx"/> but I
> need to input data base on the output from the program I'm running!

I assume you run that command via <exec>, yes?

If so, you can set a property to the output of your command (<exec>'s
outputpropoperty attribute) and later use that property inside <arg>.

Stefan

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Run time commands

Posted by Oisin Kim <oi...@aurium.net>.
Hi Stefan,

Thanks for the reply, 

I'm using the <java..../> tag to call run a class which then reads reads
some properties files and runs some other java classe(s) using
reflection, not the exec command.  I have seen the <exec> command but
thought it wasn't as clean a solution as using <java>.

The excerpt from the ant XML file is:

<target name="test" depends="module-test">
    <java classname="net.aurium.harness.Harness"
dir="${ant.project.name}" fork="true">      
        <classpath refid="aurium.classpath"/>
        <arg value="aurium.properties"/>
        <arg value="tests.txt"/>
        <arg value="-m"/>
    </java>
</target>

The module-test simply builds the classes the net.aurium.Harness will
run using reflection.

As I mentioned to Kevin off-list, the command line question is actually
a simplification of the real problem, but I'd hope I wan't too wrong
when I made the simplification, as I think they're related.  The thing I
didn't mention is that I'm also using JNI to receive native Event calls
from a MFC/C++ application, the MFC application is frozen as I start it
from one of the relfected classes and it seems that Ant won't allow me
to use runtime data input to the running application from commandline or
from this MFC app.

Apologies if I've misled you with my original question, I was hoping
someone would know a solution to the simpler version I gave first and I
could work the rest out myself!

Thanks again for the reply,

Oisin



-----Original Message-----
From: Stefan Bodewig [mailto:bodewig@apache.org] 
Sent: 17 April 2002 10:52
To: ant-user@jakarta.apache.org
Subject: Re: Run time commands


On Wed, 17 Apr 2002, Oisin Kim <oi...@aurium.net> wrote:

> I know I can pass inputs using an argument <arg value="xxx"/> but I
> need to input data base on the output from the program I'm running!

I assume you run that command via <exec>, yes?

If so, you can set a property to the output of your command (<exec>'s
outputpropoperty attribute) and later use that property inside <arg>.

Stefan

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Run time commands

Posted by Stefan Bodewig <bo...@apache.org>.
On Wed, 17 Apr 2002, Oisin Kim <oi...@aurium.net> wrote:

> I know I can pass inputs using an argument <arg value="xxx"/> but I
> need to input data base on the output from the program I'm running!

I assume you run that command via <exec>, yes?

If so, you can set a property to the output of your command (<exec>'s
outputpropoperty attribute) and later use that property inside <arg>.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>