Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to interact with bash?

 
Siegfried Heintze
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I'm fully understanding your questions, sorry.

Can you please explain what exactly you are trying to accomplish?
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18012
47
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Siegfried Heintze
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic