Score:0

xargs not working as expected

vn flag

On Mac:

sudo powermetrics --samplers smc  | xargs           

Never produces any output. Without xargs, it correctly writes my computer's power metrics.

   Machine model: ...
   SMC version: ...
   EFI version: ...
   OS version: ...
   Boot arguments: ...
   Boot time: ...

Why?

I actually wanted to do

sudo powermetrics --samplers smc | ts

and it produced the same empty result. Thought this is a simpler example.

jabbson avatar
sb flag
It may help to also include what is `expected`
Ruby avatar
vn flag
A non-zero-length output is expected.
jabbson avatar
sb flag
Let's try it again. What do you expect to happen / to be output when you run the command `sudo powermetrics --samplers smc | xargs`?
Ruby avatar
vn flag
Something along the lines of `Machine model: ... SMC version: ... EFI version: ... OS version: ... Boot arguments: ... Boot time: ...` and then more output every minute or so.
A. Trevelyan avatar
id flag
@Ruby So is it that you want to be able to run the command `sudo powermetrics --samplers smc` every minute or so? It's not clear what your objective is in the original question. If you just want to run `sudo powermeterics --samplers smc` every minute or so and see a timestamp, you could just do `watch -n60 sudo powermetrics --samplers smc`. If that's not what you want, you need to explain more in your question.
Ruby avatar
vn flag
I run the command once, but it runs indefinitely, periodically writing some output. I found the problem, it must have realized it's not writing to a terminal and is buffering. A strange decision. Any way to fool it into thinking it has a terminal?
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.