PDA

View Full Version : Executing shell commands from java




ashokformac
Apr 3, 2007, 02:08 AM
how to execute a shell command from java on a mac machine..


thanks in advance



robbieduncan
Apr 3, 2007, 02:21 AM
The same way as any other machine. Via Runtime (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html) exec methods. The return a Process (http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Process.html) object which gives you access to stdin, stdout and stderr of the process. Wrap these in BufferedReader/Writer objects and you are good to go.