File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes runtime.exec Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "runtime.exec" Watch "runtime.exec" New topic
Author

runtime.exec

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29238
    
139

I wrote a method to wrap calling Runtime.exec on UNIX. I'm trying to use it to run some monitoring type commands so it's ok they are OS specific.

When I call iostat, it works as expected and I see the first four lines. (I'm running it through bash so the pipe works.) However when I run top, I get nothing back. Not an exception - just a blank. The top command with head does work as expected when I run it directly at the command line.

Any ideas?





[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 3947
    
  17

You should be consuming the process' error stream as well as its input stream. First, to prevent its buffer from filling, and second 'cause it might tell you something useful.

I normally do it in a new Thread, and have a class specifically for consuming the input and error streams. See my post in the other thread.

p.s. This is all based on the very good JavaWorld article called When Runtime.exe() won't. If you haven't read it yet you should.


Steve
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29238
    
139

Steve Luke wrote: and second 'cause it might tell you something useful.

:eek: That it did.

"TERM environment variable not set." - I still have to figure out what to do but now it's a UNIX thing and not a Runtime.exec. I imagine it's as simple as seeing what the value of that variable is when I log in at the command line.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29238
    
139

I should probably mention for anyone reading this, it is better to use "sar" than "top". I don't have the permissions needed to run sar on this particular box.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29238
    
139

Got it. The working command is:


[edited to add line break]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: runtime.exec
 
Similar Threads
Runtime.exec() on Linux
jdk1.3.0_02 PATH????????????
runtime exec of command.com mkdir malfunction
Editing the bashrc file
Run .sh file using java