简体   繁体   中英

capturing both stdout and stderr into a file and also to a console

I am trying to make a script that spits out the status on a console as well as make a log file of that. To that end, I have been using the following line in my bash script:

exec > >(tee logfile.txt)

Having this line effectively displays stdout on a console as well as store that into a logfile.txt. Now I want to capture both stdout and stderr. I tried using

exec 2>&1 >(tee logfile.txt)

and this doesn't seem to work. Why? and how can I accomplish my task?

Just reverse the order of redirections. It helps me to read them right to left:

exec > >(tee logifle.txt) 2>&1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM