File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes java program run external command on Unix Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "java program run external command on Unix " Watch "java program run external command on Unix " New topic

java program run external command on Unix

Pierre Dubeau

Joined: Feb 19, 2001
Posts: 7
How to exit from this java program which run on Unix.
Help appreciate.

here the complete code
public class RunCommand {
public static void main(String args[]) {
String s = null;
try {
// run the Unix "ps -ef" command
Process p = Runtime.getRuntime().exec("ps -ef");
BufferedReader stdInput = new BufferedReader(new
//BufferedReader stdError = new BufferedReader(new
// InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null )
// read any errors from the attempted command
//System.out.println("Here is the standard error of the command (if any):\n");
//while ((s = stdError.readLine()) != null) {
// System.out.println(s);

catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: java program run external command on Unix