Is there a standard UNIX way of writing <filename> and <lineno> to stderr unambiguously? Is there a standard UNIX way of writing <filename> and <lineno> to stderr unambiguously? unix unix

Is there a standard UNIX way of writing <filename> and <lineno> to stderr unambiguously?


The GNU "Standard" is really just a set of guidelines. However, as you have aptly noticed, not everyone follows it. In fact, I daresay that outside of GNU projects, few care to follow it.

That being said, you seem to have done the research yourself. As there is no common consensus on this topic, I would say to simply make your application easy to use. The decision you appear to have made, to use this:

<filename>, lineno <lineno>: <message>

seems fairly reasonable. I would also add the name of you application, the type of error and the code on that line, somewhat like this:

<appname>: Parsing Error: <message>    In <filename>, line <lineno>: <code>

Finally, don't write your errors to a logfile (unless the user somehow specifies that they want to; ie: command line option). Instead, write all errors to stderr. If the user wishes to, they can manually pipe stderr to a file like this:

$ python <appname>.py 2><appname>.log

which, let's say, your app was called parser, would look like:

$ python parser.py 2>parser.log