• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

runtime.exec

 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?



 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got it. The working command is:


[edited to add line break]
 
Catch Ernie! Catch the egg! And catch this tiny ad too:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic