jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Java and Shell scripts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java and Shell scripts" Watch "Java and Shell scripts" New topic

Java and Shell scripts

Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
So because the platform I'm developing a Java application for is Solaris, I need to be able to run a mount CD or USB script which is provided to me. The script will return a status code...so first question is, where do I start looking at to execute and get the status code of the script?
Second question is, if the status code is 0 (as in failure), the script will echo out some sort of meaningful error message. I would like to capture that and be able to display it in a error dialog...how would I go about capturing that.
Also (probably a little bit outside of this forum, but I'll give it a shot)...does the script run in a separate shell? Like if I have System.outs in my main program, and then run the script, will I have an issue capturing the echo outputs from the script?
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
Here's the actual script (sorry, it's a bit long...but I'm not knowledgable enough with shell scripting to know what parts are important).

What puzzles me is that there does not seem to be any status or exit if the mount of the CD is successful or not which leads me to believe that there needs to be some work done on the script.
Nevertheless, if someone can decipher this stuff and help me out, it would be greatly appreciated.
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 692
Look at the Process class. It will run a command and allow you to get its output with various methods.

The script looks like it returns a 0 on success and a 1 on failure.
Eric Chang
Ranch Hand

Joined: Jan 27, 2004
Posts: 113
Excellent, thanks for pointing me in the right direction!
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46352
Originally posted by Norm Radder:
Look at the Process class.
More discussion about running Processes here, and in the associated links in that thread.
I agree. Here's the link: http://aspose.com/file-tools
subject: Java and Shell scripts
It's not a secret anymore!