File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to exceute multiple commands using java runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to exceute multiple commands using java runtime" Watch "How to exceute multiple commands using java runtime" New topic
Author

How to exceute multiple commands using java runtime

syruss kumar
Ranch Hand

Joined: Jul 23, 2009
Posts: 98

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.

All search starts with beginner's luck and all search ends with victor's severly tested.
Richard Tookey
Ranch Hand

Joined: Aug 27, 2012
Posts: 1111
    
  10

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

Joined: Jul 23, 2009
Posts: 98


Thanks Richard, as you said i need to execute a set of commands and capture that output in a java program.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to exceute multiple commands using java runtime