LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Redirecting STDERR (https://www.linuxquestions.org/questions/linux-newbie-8/redirecting-stderr-575820/)

iceman_san 08-09-2007 02:08 AM

Urgent
 
pls somebody help with this ,

how to redirect the the STDERR to a file and to STDOUT simultaneously, ie if an error occurs the error message should be displayed on the screen as well as append to a file specified....

acid_kewpie 08-09-2007 02:23 AM

please do not mark threads as urgent. it is not urgent for any of the members who kindly donate their time to help others here. in future use descriptive titles which relate to your question.

b0uncer 08-09-2007 02:48 AM

There may be several methods, one would be to just put stderr into a file, and append another command to the line that, if error occurs, cat'ed the error file (for example || cat errors.txt).

EDIT: also check program 'tee', it could help too (or then not; I think it's easier to just redirect stderr to a file, and then cat it in case of error).

jf.vdbosch 08-09-2007 03:55 AM

writing to stdout and a file
 
Hello,
I think you should use tee

if you were sorting to a printer you could write
sort inputfile | lp

if you use tee it looks like
sort inputfile | tee logfile | lp

now the result of the sort is not only sent to te printer but also written in the file logfile

Regards, Hans.

iceman_san 08-09-2007 07:09 AM

sorry but my requirement is different , the file is a log file , so i cannot cat all the details to the terminal , so can u tell me any other possibilities thanks in advance:)

b0uncer 08-09-2007 07:28 AM

Ok, instead of catting the whole file you could also use tail (or head, if you do thinks standing on your head) to print last X lines for example..but now you probably mean that you don't know how many lines the error produces, so you don't know exactly how many lines you would want to read, and don't want to read too much either.

Well, second way I can think of, thought not as easy as the first one, would be to send stderr to a variable, then print that variable to screen and echo it to a file. Never tried myself (have not needed), good luck :)

iceman_san 08-09-2007 07:37 AM

sorry , i want to display ti it to terminal , i am giving this command:-

system("/usr/atria/bin/clearmake @ARGV") |"tee -a /tmp/cclogs/$userid.$time.log"|`>&1` ;

any suggestions ??

iceman_san 08-09-2007 07:47 AM

can u be more specific

pixellany 08-09-2007 07:55 AM

http://tldp.org/LDP/Bash-Beginners-G...ect_09_04.html

I highly recommend this book--you can download a .pdf if you don't like reading on-line.

chrism01 08-09-2007 06:41 PM

Looks like a Perl cmd.
Put the whole thing inside the system() cmd and remove the second pipe symbol.
Also drop the single quotes at the end.

iceman_san 08-10-2007 12:27 AM

system("/usr/atria/bin/clearmakeold @ARGV | >> /tmp/cclogs/$userid.$time.log 2>&1") ;

I have the whole thing within system , but the STDERR was displayed to terminal , but not copied to the file , any help ??

chrism01 08-10-2007 12:43 AM

You still need the 'tee' cmd to make it output to 2 different places simultaneously.

iceman_san 08-10-2007 01:46 AM

ok, where should i put the tee command ?? can you specify to me ??

iceman_san 08-10-2007 02:20 AM

thanks a lot :-)

i put the tee command instaed of the rediretion , and
firstly i redirected the STDERR to STDOUT adn later did tee-a to the file and got what i need, once again thanks for u r support


All times are GMT -5. The time now is 10:34 AM.