• 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

Executing unix commands from java application

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at Runtime.exec().
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic