2

EDIT: I was chastised for being off subject. I edited out the file method I used as an example and inserted C++ method from reality.

I am using C++ popen to issue a top command to get system information into my program, then into an xml file I can send off-system. I parse the output of top into various variables (painful bit of code) which get poled into the xml.

top very helpfully truncates it's output's width to fit on the screen even in batch mode where the output is redirected to a pipe.

popen( "top -b -n 1", "r" ); 

Works the same if the output is sent to a file.

Is there a way to tell top to show all its fields (in batch mode) even if they would fall off the right side of the screen?

NOTE: In my particular case, I ran my c++ top-parser on my workstation and got, say, 15 columns per PID. Then I changed to fewer characters in the line (bigger text). I completely lost the 15th field. Then I tried an in-between font and got all but one column of the 15th field back. That field ends in %st and I count on it saying that, not %s. Fixing this need to be generic, not based on individual cases.

Thanks for the help. I checked Google and it knows much about top, but just how to ask.....

NB: If you'd like to see this phenomenon, run top in your usual command window capturing the output to a file or pipe, then change the font in the window to have more characters on each line of the terminal window and rerun the command.

Wes Miller
  • 2,191
  • 2
  • 38
  • 64

1 Answers1

3

Try setting COLUMNS environment variable:

$ COLUMNS=10000 top
Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
  • Great idea. Put lots of extra space on the end of the on-screen lines (I used 1000, not 10000, thank God). Sadly, it didn't make it into the file. Almost like I need to set **COLUMNS=1000 >** except, of course, you can't co that, at least not using that syntax. – Wes Miller Jul 26 '12 at 13:08
  • My error. This did work when I realized that a pipe might actually work differently than a file. Change the code to read, popen( "export COLUMNS=100; top -b -n 1", "r" ); – Wes Miller Jul 30 '12 at 11:37