The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-14-2001
QUartz Ite QUartz Ite is offline
Registered User
  
 

Join Date: Oct 2001
Posts: 4
Question Java program calling a UNIX command

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
  #2 (permalink)  
Old 11-14-2001
rwb1959's Avatar
rwb1959 rwb1959 is offline
Registered User
  
 

Join Date: Aug 2001
Location: Virginia, USA
Posts: 438
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);
}

...
  #3 (permalink)  
Old 11-15-2001
QUartz Ite QUartz Ite is offline
Registered User
  
 

Join Date: Oct 2001
Posts: 4
Thanks,
That does the trick nicely
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:48 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0