Why does dos2unix print to stderr?

When running dos2unix in a file, I get the following listing to the terminal

dos2unix: converting file <filename> to UNIX format ... 

In an attempt to suppress the output by sending it to / dev / null, I noticed that it was sent to stderr instead of stdout, as I expected (since it looks like a normal message, not an error). Is there a reason for this?

+7
linux dos2unix
source share
5 answers

In Unix-like environments, a process chain usually occurs: the result of one program is used as input for another program. Mixing the results with the diagnosis would confuse the next stage of processing. It will also hide the diagnostics from the potential user watching the terminal, where the processing results transferred to the next program are not displayed.

This is the reason for the separation of results and diagnostics in the stdout and stderr standards. Diagnostics is not limited to errors, but should contain everything that is not the result of processing expected in subsequent programs.

Regarding the urgent issue: dos2unix is ​​often used to convert files in place, but can also be displayed on stdout (when called without a file name, it reads from stdin and displays on stdout). Then stdout can be redirected independently of stderr. Consider cat blados | dos2unix > blaunix cat blados | dos2unix > blaunix . You will still see diagnostics (which may contain error messages!), But the result of the processing will go to blah bis.

It is not so often to print diagnostics at all if successful - probably a small adaptation to DOS users. It would be nice if the processing result contained an informational message; for example, he would break the C file.

+5
source share

There is no reason, but usually stderr is not just for error output. This is another thread that is often used for logging or informational messages. Since the log message is not displayed, it is not sent to stdout , which is the result of the program results.

The reason it is printed on your terminal is a consequence of your shell and is not controlled by the application.

+6
source share

Just because it was implemented that way ...

If you check the source code , you will see:

 ... if (!pFlag->Quiet) fprintf(stderr, _("dos2unix: converting file %s to file %s in UNIX format ...\n"), argv[ArgIdx-1], argv[ArgIdx]); ... 
+3
source share

I am using this single line file to redirect stderr to stdout, skip the first irrelevant line I received and send the rest back to stderr.

dos2unix thefile 2>&1|tail -n+2 1>&2

+1
source share
 Try dos2unix -q <filename> 

-q, --quiet Quiet mode. Disable all warnings and messages. The return value is zero. Except when using the wrong command line options.

0
source share

All Articles