aspose file tools*
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
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: 16058
    
  21

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