Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Executing unix commands from java application

 
Harish Tiruvile
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at Runtime.exec().
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic