Java and UNIX pipes

P

potato

A quick newbie question... is it possible to use a unix pipe to provide
the argument to a java program. Eg How do I get this to work from a
bash shell for example.....

someArgument|java -classpath /externaltest/bin/ test.PipeTest

Thanks for any help.
 
T

Thomas Hawtin

potato said:
A quick newbie question... is it possible to use a unix pipe to provide
the argument to a java program. Eg How do I get this to work from a
bash shell for example.....

someArgument|java -classpath /externaltest/bin/ test.PipeTest

java -classpath /externaltest/bin/ test.PipeTest `someArgument`

IIRC you can use $( ) as well, but I don't like to type so much.

Tom Hawtin
 
C

Chris Head

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
A quick newbie question... is it possible to use a unix pipe to provide
the argument to a java program. Eg How do I get this to work from a
bash shell for example.....

someArgument|java -classpath /externaltest/bin/ test.PipeTest

Thanks for any help.

Hi,
Note Thomas's reply; however, if you actually wanted to know how to get
data piped to your program as you showed above, the answer is to use
System.in. You probably want to wrap it in an InputStreamReader. You
might also want to wrap that in a BufferedReader and use the readLine()
method.

Chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32)

iD8DBQFC4SQYgxSrXuMbw1YRAnGbAKDLmmYd3uSYCq4iLJ7GezbC5fMGHwCaAioS
2YGYWAGpUu7LgkERTZzsC1c=
=wDUh
-----END PGP SIGNATURE-----
 
J

Joan

potato said:
A quick newbie question... is it possible to use a unix pipe to provide
the argument to a java program. Eg How do I get this to work from a
bash shell for example.....

someArgument|java -classpath /externaltest/bin/ test.PipeTest
look into "xargs"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top