Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2008

Tip: Looking for answers? Try searching our database.

Scripting input from linux to java process

Thread view: 
andersonanderson@gmail.com - 26 Sep 2008 21:11 GMT
Is there anyway to script though a bash script or something alike the
user input to a java process..?

I tried something like

echo "Starting..."
bash /opt/dir/myjavaprocess << EOF
test1
test2
test3

It always seems to just get the first line and then have a lot of
returns or something?

I also tried

(echo "test 1\
test2\
test3
|  /opt/dir/myjavaprocess)

and it seemed to do the same thing?
John B. Matthews - 27 Sep 2008 02:23 GMT
In article
<602a6f77-0938-4e99-998d-344e8604ec3d@k36g2000pri.googlegroups.com>,

> Is there anyway to script though a bash script or something alike the
> user input to a java process..?
[quoted text clipped - 18 lines]
>
> and it seemed to do the same thing?

<console>
$ javac FilterStream.java ; java FilterStream < FilterStream.java
/**
* Copy stdin to stdout, byte by byte.
* @author John B. Matthews
*/
import java.io.*;

public class FilterStream {
   public static void main(String[] args) throws IOException {
       BufferedInputStream in = new BufferedInputStream(System.in);
       int c;
       while ((c = in.read()) != -1) {
           System.out.write(c);
       }
   }
}
$ cat test.sh
#!/bin/sh
java FilterStream << EOF
one
two
three
EOF
$ ./test.sh
one
two
three
</console>
Signature

John B. Matthews
trashgod at gmail dot com
home dot woh dot rr dot com slash jbmatthews

Nigel Wade - 29 Sep 2008 14:33 GMT
> Is there anyway to script though a bash script or something alike the
> user input to a java process..?
[quoted text clipped - 18 lines]
>
> and it seemed to do the same thing?

What is /opt/dir/myjavaprocess? You are running it with bash which would suggest
that its a shell script, but what does it do?

Using hereis input redirection works with java and a simple script which runs
java. Perhaps your shell script is messing with the input stream.

Signature

Nigel Wade



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.