View Ticket
Not logged in
Ticket Hash: b67135df9d2263bf878a16ddbcc8c5c21055ad66
Title: importSHP, exportSHP and DBF writing to stderr
Status: Closed Type: Code_Defect
Severity: Cosmetic Priority: Zero
Subsystem: Resolution: Rejected
Last Modified: 2016-11-26 10:31:24
Version Found In: 4.3.0a
User Comments:
anonymous added on 2016-09-22 16:48:59:
I am accessing spatialite via Python using the sqlite3 module. It is working very nicely except in spatialite 4.3.0a in spatialite.c calls to dump_shapefile load_shapefile_ex2 are called with verbose=1 which causes it to write to stderr.

It would be nice if there were some way to control this either in the SQL or by setting some global override maybe like:

select spatialite_config('verbose', 0);

or something like that. Or maybe the default should just be that is off in the released code.

-Steve

mj10777 added on 2016-09-23 03:19:39:

I assume that following is meant:
load_shapefile_ex3:

    if (verbose)
	spatialite_e
	    ("========\nLoading shapefile at '%s' into SQLite table '%s'\n",
	     shp_path, table);

In src/headers/spatialite/debug.h
    spatialite_e
    spatialite_i
    and in debuging modus: spatialite_d
are defined as macros.
    so influencing this during run-time is difficult
'i' and 'd' (when active) are sent to stdout
'e' is sent to stderr

The extra 'information' message sent with 'verbose' is sent to stdout
    so that it will not interfer with normal data output.
When desired, the user can redirect non-data output to '/dev/null'
    without interfering with desired output

Since stderr is a standard output, redirecting it should be no problem.

As a non-Python expert, I quickly found the following, Cross-platform, solution at:
    http://stackoverflow.com/questions/6735917/redirecting-stdout-to-nothing-in-python
import os
import sys
f = open(os.devnull, 'w')
sys.stdout = f
Replacing os.devnull with 'error.script_name.txt' might be considered useful.
Calling a python-script (same page with stdout ['>' or '1>']) with stderr ['2>'] is also easy:
# real world:
python myprogram.py 2> /dev/null
# windows world:
python myprogram.py 2> nul
With the use of '1>/dev/null 2>&1'
    both outputs will be transported to the 'land of nothing'

These methods have existed since the beginning of unix in the 1960's
Separating data-output and any extra information/errors between stdout and stderr also.

Conclusion:
This is the desired behavior and not an error.
The desired effect of removing the undesired output can
    easily be accomplished by the user in a standard, designed way


mj10777 added on 2016-09-23 03:22:58:

I will defer the final decision on this to Sandro.