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/CABx2%3DD9POoqxgftj505parnpqm2o6EVRGQm-TZ7iJYmN%2BJ_%3Dwg%40mail.gmail.com.

Reply via email to