This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Ant, Maven and Other Build Tools and the fly likes How to interact with bash? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "How to interact with bash?" Watch "How to interact with bash?" New topic
Author

How to interact with bash?

Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
(1) Can I write a java program that reads from standard input and run it from ant? Can I control if standard input is a <![CDATA[ ]]> embedded in the ant file or the bash script?

Perhaps something like this:


(2) Can I write an ant script that return the class path to the calling bash script so the bash script can run the java program directly? Maybe something like this:



How could I return a string from build.xml that I could then use in bash?

Thanks,
Siegfried
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I'm not sure I'm fully understanding your questions, sorry.

Can you please explain what exactly you are trying to accomplish?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15960
    
  19

You can probably set up an Ant script to compile and invoke a Java application, if that's what you mean, but that would not be pretty.

You can definitely set up a task in an Ant script that invokes a Java application (or for that matter, non-java applications. And it can obtain input from any source it desires, including the "here data" that you showed in your example (just read stdin from Java).

In some cases, it's preferable to make your application runnable as an actual Ant custom task, which is actually quite easy. Some apps I know of even run both standalone and as Ant custom tasks, depending on how you invoke them.

CDATA isn't needed in a shell script, but it's a good idea if you embed the stdin stream in the Ant script itself, since that's an XML file and you don't want the magic XML characters being misinterpreted if they are used in the embedded data.


Customer surveys are for companies who didn't pay proper attention to begin with.
Siegfried Heintze
Ranch Hand

Joined: Aug 11, 2000
Posts: 381
You can definitely set up a task in an Ant script that invokes a Java application (or for that matter, non-java applications. And it can obtain input from any source it desires, including the "here data" that you showed in your example (just read stdin from Java).


And when reading from standard input what am I reading? Text in the build.xml or text in the bash script?

Let me explain my other question again:

C/C++ programmers can create a program xyz.cpp with the contents "int main(){ return EXIT_SUCCESS; }" and bash programmers can fetch that integer value EXIT_SUCCESS with the code

./xyz.exe # I'm a wierdo, I like the exe extension from the windows world
result = $!
if [ $result == 0 ]
then
echo "program xyz ran"
else
echo "program xyz failed"
fi

(1) How do I do this when calling java directly from bash?
(2) How do I do this when calling java indirectly via ant?
(3) Can I communicate something back to the bash shell other than an integer value? How about a string?

Thanks,
Siegfried

Thanks,
Siegfried
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to interact with bash?
 
Similar Threads
Automating Command Line installation
How to detect EOF when using java.io.BufferedReader?
Pass Data to outputstream
Checking for .jar in classpath with ANT
system.exit