Another option is to employ the Python subprocess package.
Also, one needs to know where the ogrinfo.exe file is located.
After executing one of the following commands:
import subprocess command = "C:/OSGeo4W/bin/ogrinfo.exe -so -al D:/qgis_test/points_4326.shp" output, error = subprocess.Popen(command, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ).communicate() print(output)
or
import subprocess command = "C:/OSGeo4W/bin/ogrinfo.exe -so -al D:/qgis_test/points_4326.shp" output = subprocess.check_call(command) print(output)
It is possible to get such an output:
INFO: Open of `D:/qgis_test/points_4326.shp' using driver `ESRI Shapefile' successful. Layer name: points_4326 Metadata: DBF_DATE_LAST_UPDATE=2023-11-20 Geometry: Point Feature Count: 3 Extent: (-58.497423, -34.726643) - (-58.495246, -34.725891) Layer SRS WKT: GEOGCRS["WGS 84", DATUM["World Geodetic System 1984", ELLIPSOID["WGS 84",6378137,298.257223563, LENGTHUNIT["metre",1]]], PRIMEM["Greenwich",0, ANGLEUNIT["degree",0.0174532925199433]], CS[ellipsoidal,2], AXIS["latitude",north, ORDER[1], ANGLEUNIT["degree",0.0174532925199433]], AXIS["longitude",east, ORDER[2], ANGLEUNIT["degree",0.0174532925199433]], ID["EPSG",4326]] Data axis to CRS axis mapping: 2,1 id: Integer64 (10.0) city: String (15.0)
References:
from osgeorather thansubprocess. Is this not the case?subprocessis the route. If you want to do the equivalent in Python, then you need to rewrite the Question to ask that.