I was wondering if it was possible to call a unix command directly from a Java program during run-time. This command could very very basic e.g. "ps -ef" returned as a string, all I need is a starting place so if anyone has any suggestion or examples I would be very grateful
A good example of what you want is at...
http://www.devdaily.com/java/edu/pj/pj010016/pj010016.shtml
...the code snippit...
...
// 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\);
\}
...
Thanks,
That does the trick nicely:D