This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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
Author

java program run external command on Unix

Pierre Dubeau
Greenhorn

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

here the complete code
import java.io.*;
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
InputStreamReader(p.getInputStream()));
//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 )
{
System.out.println(s);
}
// 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);
//}
stdInput.close();

System.exit(0);
}
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
System.exit(-1);
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java program run external command on Unix
 
Similar Threads
help with running dos commands using java
executing linux commands through java socket
How to connect to Linux using Java code?
Pesky Runtime method
Having trouble in running a unix command and getting the output