This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes return a value from shell script to java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "return a value from shell script to java program" Watch "return a value from shell script to java program" New topic
Author

return a value from shell script to java program

yuga devi
Greenhorn

Joined: Aug 07, 2008
Posts: 22
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

Joined: Jun 25, 2001
Posts: 15951
    
  19

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.


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

Joined: Jun 02, 2003
Posts: 1923

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.


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: return a value from shell script to java program
 
Similar Threads
getting and setting environment variables
How to return a value from java to script
how to get result from java when java thread is running in background
Return value from main
Printing a file using Shell Script in Unix env called from a Java Application