• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

return a value from shell script to java program

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
reply
    Bookmark Topic Watch Topic
  • New Topic