aspose 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
JavaRanch » Java Forums » Java » Java in General
Bookmark "runtime.exec" Watch "runtime.exec" New topic
Author

runtime.exec

Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

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: 4181
    
  21

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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30749
    
156

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