[gdal-dev] help printing the standard out from gdal_grid in python

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] help printing the standard out from gdal_grid in python

Nicolas Cadieux
Hi,

I am not an experienced programmer.  I am calling gdal_grid from a
python script.  I am using p.imap_ unordered to multiprocess the
script.  The idea is the following:

--------------------

def gdal_Grid(fileList):
     gdal_Grid_Cmd = 'gdal_grid -l ....'
     shell = subprocess.Popen(r'c:\OSGeo4W64\OSGeo4W.bat',
stdin=subprocess.PIPE)
     shell.communicate(gdal_Grid_Cmd)
     return  'done'

-------------------------

lst = [c:\temp.csv....]

if __name__ == '__main__':
     p = Pool(2)
     for x in p.imap_unordered(gdal_Grid,lst):
         print x


The Question:
I would like to print the output (standard out???) from gdal_grid. I
can't figure how to use stdout=subprocess.PIPE. Can you help me?
Thanks
Nicolas

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: help printing the standard out from gdal_grid in python

Sean Gillies-3
Hi Nicolas,

check_output() is higher level and easier to use. I recommend it: https://docs.python.org/2.7/library/subprocess.html#subprocess.check_output. There's a note in there about capturing stderr as well. If gdal_grid is running successfully, there may not be anything in stdout.

I think I see a bug in your code. The function you give to the pool should take a single arg, not a list. imap_unordered() will pass elements of your list to workers, not the entire list.

Good luck!

On Thu, Apr 12, 2018 at 9:13 AM, Nicolas Cadieux <[hidden email]> wrote:
Hi,

I am not an experienced programmer.  I am calling gdal_grid from a python script.  I am using p.imap_ unordered to multiprocess the script.  The idea is the following:

--------------------

def gdal_Grid(fileList):
    gdal_Grid_Cmd = 'gdal_grid -l ....'
    shell = subprocess.Popen(r'c:\OSGeo4W64\OSGeo4W.bat', stdin=subprocess.PIPE)
    shell.communicate(gdal_Grid_Cmd)
    return  'done'

-------------------------

lst = [c:\temp.csv....]

if __name__ == '__main__':
    p = Pool(2)
    for x in p.imap_unordered(gdal_Grid,lst):
        print x


The Question:
I would like to print the output (standard out???) from gdal_grid. I can't figure how to use stdout=subprocess.PIPE. Can you help me?
Thanks
Nicolas

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev



--
Sean Gillies

_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev