This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

runtime.exec

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?



 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34410
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it. The working command is:


[edited to add line break]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic