• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

return a value from shell script to java program

 
yuga devi
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to get the return value of a shell script program in a java file.

For ex, my shell script is as follows:

return grep 'success' Test.log

which will return say , lines in 1000. [without redirecting to any file]

I am executing this script from a java file.

I want to get this return value from my java file.

--yuga

 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The term "java file" is a bit confusing. It sounds like you want to execute a script using the Java Runtime.exec() method.

To get the output into the calling Java app, just reassign the stdout stream that the Runtime.exec will write to. You can probably stream to a StringBuffer. Then, when the script has returned, get the results from the StringBuffer.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you start your program with that command, you might pipe the result of grep to your program:

while your program reads from System.in.

Else using FileInputStream, and pattenmatching against (".*success.*") will be more easy than runtime.exec, better debuggable, and portable.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic