1

I wanted get the resout of ps command to a file like this. (in bash)

$ps -eax |& tee list1 

and I see many lines from the ps command but the file list1 is empty.
How should I do it?

13
  • what was the intention behind using |&? Commented Aug 31, 2022 at 12:48
  • I usually did to catch stderr too. Commented Aug 31, 2022 at 12:50
  • the problem is I can't reproduce this locally; my list1 is filled with the output of ps. So I thought maybe I was doing something wrong, and hence I asked for clarification. Commented Aug 31, 2022 at 12:54
  • 1
    Note that you need bash 4.0 or newer for |& (short for 2>&1 |, |& being a csh operator initially). In older versions, I'd expect a syntax error though. Commented Aug 31, 2022 at 12:55
  • maybe we need to do a sanity check on tee. What does type tee say? And tee --version? Commented Aug 31, 2022 at 12:55

1 Answer 1

0

To get your desired logging in parallel to terminal output, you should change

$ps -eax |& tee list1 

to

$ps -eax 2>&1 | tee list1 

As suggested by the discussion, it is possible that the "|&" operator is not implemented in a universal fashion, causing discrepancies from one system to the next, or that it is reacting to unspecified environmental conditions.

1
  • Hi, I tried $ps -eax |& tee list1 again and it works today! I don't know why. Commented Sep 20, 2022 at 3:01

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.