I have a processing tool that helps users to export data from PostGIS tables to GPKG. I am using ogr2ogr commands to achieve the tasks. I am calling the commands via subprocess. However, I cannot print out in the log window of the tool any error that may occur while executing the ogr2ogr. Is there any way to capture errors and display them in the log window? For now, the best I could do is a configuration option to create a log file at the end
-debug on --config CPL_LOG C:\Users\Export.log'
import subprocess
import asyncio
import time
outFile = r"C:\Users\INPUT_DATA.gpkg"
bwk_views = [
('view_1', 'output_1', 'POLYGON')
,('view_2', 'output_2', 'LINESTRING')]
commands = []
for view in bwk_views:
layer_name = view[1]
commands.append(
f'ogr2ogr -update -append -f GPKG "{outFile}" PG:service=XX -sql "SELECT * FROM wlk.{view[0]}" -nln {layer_name} -nlt {view[2]} -a_srs EPSG:31287' )
async def export(delay, command):
await asyncio.sleep(delay)
subprocess.run(command, shell=True)
async def main():
# Wait tasks are completed one after another
for i, command in enumerate(commands):
await export(i, command)
asyncio.run(main())