Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to exceute multiple commands using java runtime

 
syruss kumar
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • 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.
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • 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: 107
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic