XY Problem.... I'll be using that in the future :-) Yeah, I just wanted to see those stats and thought I would write a go app to do it just for the sake of writing some go code. It's not important. Thanks for the info.
On Thu, Jan 28, 2021 at 2:08 PM Kurtis Rader <kra...@skepticism.us> wrote: > On Thu, Jan 28, 2021 at 9:29 AM Jeff Mangan <j...@magentatech.com> wrote: > >> I am trying to get the results of top (more specifically htop) but every >> time it prints nothing, whereas any other command (ls, pwd, etc...) returns >> the output fine. My objective is to get access to the process stats that >> are returned to the screen. >> > > Note that htop is screen oriented, not line oriented. That is, it uses > terminal escape sequences to move the cursor and change the color of the > text. Run > > echo q | htop > x > > Then look at the content of file "x". You won't see lines of text like > you would from the output of a command like ls. You could use Go package > github.com/creack/pty to communicate with htop via a pseudo-tty and > "screen scrape" its output. But that would be a really painful way to get > information about running processes. It's hard to provide useful advice > because it appears you've made the "XY Problem <https://xyproblem.info/>" > mistake. Depending on what information you really want and the platform > you're running on the answer may be as simple as running "ps waux" and > capturing the %CPU column. > > -- > Kurtis Rader > Caretaker of the exceptional canines Junior and Hank > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAHr9bga_ckmcgEeN5%3DmTdL-i2S1onMNdyFtU8V2ZQGcqy-1hdw%40mail.gmail.com.