• 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
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

How to exceute multiple commands using java runtime

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi all,

I tried to exceute shell commands through java program using runtime.



If i execute this code, the terminal is opened but the "pwd" command is not working.Can anyone shed some light on this?.

Thanks in advance.
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A 'man' of gnome-terminal will show you one thing that is wrong; it indicates that you need to supply the command either with an "--execute" or "--command" argument BUT I suspect this will not solve your problem since I doubt that you just want a transient flash of a gnome terminal to appear. I'm betting that what you actually want to do is run a set of commands in a bash shell and collect the output in your Java program. In this case you need to do a man of 'bash' and then read the 4 sections of http://www.javaworld.com/jw-12-2000/jw-1229-traps.html and implement ALL the recommendations.

Note - you can supply the bash commands either as a command line argument to bash or though the bash stdin; the man page has the details. If you want to supply multiple commands to bash then it is usually best to write them to the bash stdin.
 
syruss kumar
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Thanks Richard, as you said i need to execute a set of commands and capture that output in a java program.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic