d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Question About Programming/unix Scripting.
Add Reply New Topic New Poll
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Feb 21 2013 01:16pm
So one of the things our Professor has told us about is using a command, like

Code
exec 2> some_file



And putting it at the end of a script or something. So I have an idea of what this does roughly (takes the stderr output from the script you ran it in and sends it to some_file), but what all will it catch specifically?

For scripts does it make sense to use this instead of try/catch blocks? (If they even exist in korn shell, I don't know yet)

Also, is there a similar functionality for modern high level languages like c++/java? Something that will just take all the errors from stderr and funnel them somewhere?

This post was edited by Eep on Feb 21 2013 01:18pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 21 2013 01:56pm
programs only write to stderr if they were made to. you most likely never knew it but, cin is stdin, cout is stdout, cerr is stderr. only when you write to cerr will anything be written to it.

now for most standardized linux applications they do write their errors to stderr. take gcc for example. any errors during compiling will be sent to stderr.

as for it itself it does not add any form of error handling it simply pipes all output from stderr to a file (or if you use 2>&1 i believe it is you can pipe all errors to stdout).

the reason why one would want to pipe errors to a file is so that he could view the errors later or potentially parse the logfile for specific errors.

should read that link i posted in your other bash thread. it explains all these perfectly well.

This post was edited by AbDuCt on Feb 21 2013 01:59pm
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Feb 21 2013 03:23pm
Quote (AbDuCt @ Feb 21 2013 02:56pm)
programs only write to stderr if they were made to. you most likely never knew it but, cin is stdin, cout is stdout, cerr is stderr. only when you write to cerr will anything be written to it.

now for most standardized linux applications they do write their errors to stderr. take gcc for example. any errors during compiling will be sent to stderr.

as for it itself it does not add any form of error handling it simply pipes all output from stderr to a file (or if you use 2>&1 i believe it is you can pipe all errors to stdout).

the reason why one would want to pipe errors to a file is so that he could view the errors later or potentially parse the logfile for specific errors.

should read that link i posted in your other bash thread. it explains all these perfectly well.


I made a bash thread?
Member
Posts: 23,862
Joined: Aug 16 2006
Gold: 20.00
Feb 21 2013 04:12pm
Quote (Eep @ Feb 21 2013 04:23pm)
I made a bash thread?


also thanks for the reply. I see what you mean now. Try/catch still necessary for programs to handle errors.

I guess in a program (rather than a script) you would want to have each try/catch block send errors they find down cerr to a file as well? Seems a little tedious to do it for every block.

Go Back To Programming & Development Topic List
Add Reply New Topic New Poll