![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Connection problem with gui java program to postgreaql database using unix | uci | UNIX for Dummies Questions & Answers | 2 | 12-15-2007 09:16 AM |
| executing the su command from a java program. | shailendrat | UNIX for Dummies Questions & Answers | 1 | 03-24-2005 12:27 PM |
| calling a script from java | javierelizabeth | UNIX for Dummies Questions & Answers | 1 | 03-05-2004 10:56 AM |
| Executing UNIX command from java on NT | CJ Walt | UNIX for Dummies Questions & Answers | 1 | 06-25-2003 01:39 PM |
| java errors when calling from cron | mntamago | Shell Programming and Scripting | 3 | 11-18-2002 09:50 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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.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); } ... |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|