aspose file tools*
The moose likes Java in General and the fly likes Executing unix commands from java application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Executing unix commands from java application" Watch "Executing unix commands from java application" New topic
Author

Executing unix commands from java application

Harish Tiruvile
Ranch Hand

Joined: Dec 01, 2005
Posts: 99
Hi ,

can anyone tell me how to write java application which will execute linux-commands from java application (i.e, without opening command window manually)..
My Question: Is it possible to execute Linux-commands from java application.

Normally we open command window manually and execute commands in command window...Here i want to make my java program to execute command and retrieve resultant data ..Is it possible to execute linux-commands from java application?
If anyone know answer please assist me.


Giving up is the easiest thing in the world to do..but holding it together when everything seems like falling apart is true strength!!
with regards, Harish.T
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
Take a look at Runtime.exec().
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Here's a good article that covers reading the stdout and errout streams, an essential part for some commands.

New in Java 5: ProcessBuilder is a friendlier wrapper around Runtime.exec()
[ August 31, 2006: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Srinivas Kalvala
Ranch Hand

Joined: Oct 20, 2005
Posts: 257

Hello,

have a look at Runtime.exec() and process() commands.

One Hint: Always clear the input and output streams of these two methods to avoid hands in execution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing unix commands from java application