File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How to run unix command using Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to run unix command using Java" Watch "How to run unix command using Java" New topic

How to run unix command using Java

Manohar Chhapolia

Joined: Nov 22, 2006
Posts: 17
Hi all,

I have two queries regarding execution of java program on Solaris.

1. Can we run UNIX command using Java and get the output back to Java for the further analysis?
2. Can we run it from one JVM (first UNIX machine) to another JVM (second UNIX machine)? (Actually, I want to run same script on many Solaris and get the out for further analysis)

Thanks and Regards,
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 443

The answer to 1. is yes and google java class ProcessBuilder similarly google for some examples you'll find a lot of them on the net and they work fine with Solaris though user accounts and shells can be fun ;-)

"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

And always remember to read the javaworld article "Why Runtime.exec() doesn't"

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
I agree. Here's the link:
subject: How to run unix command using Java
jQuery in Action, 3rd edition