samedi 3 janvier 2015

output both stderr and stderr on consle and store them in a file at same time


may I output both stdout and stderr on console screen and store one of them into a log file?


I write a test shell script:



#!/bin/sh

echo OUT! >&1
echo ERR! >&2


I can output both of them on screen just by run the script:



$./test
OUT!
ERR!


I can output stderr and catch stdout into log file by:



$./test | tee 1>log
ERR!

$cat log
OUT!


I can output nothing but catch all stdout and stderro into log file by:



$./test 2>&1| tee 1>log

$cat log
OUT!
ERR!


I can output both of stdout and stderr and catch all of them into a log file by:



$./test 2>&1 | tee log
OUT!
ERR!

$cat log
OUT!
ERR!


I can output both can catch stdout into log file by:



$./test | tee 2>&1 log
ERR!
OUT!

$cat log
OUT!


My questions are:



  1. how to just output stdout and catch stderr into file?(I tried ./test|tee 2>log, but doesn't work)

  2. how to just output both and catch stderr into file?



Aucun commentaire:

Enregistrer un commentaire