[GRASS-user] python pipe Popen to grass.<?>_command

Greetings,

I’m attempting to pipe the results from:
pts=sub.Popen(‘las2txt -i %s --parse xyz --keep-classes 2 --delimiter “|” --stdout’%path, shell=True, stdout=sub.PIPE)

to the appropriate grass.?_command(‘r.in.xyz’, etc…)

i’ve tried the following:

mkInRast=grass.feed_command(“r.in.xyz”, input=pts.communicate()[0], output=‘tester’, method=‘mean’)

which results in:

Traceback (most recent call last):
File “”, line 1, in
File “/usr/lib/grass64/etc/python/grass/script/core.py”, line 198, in feed_command
return start_command(*args, **kwargs)
File “/usr/lib/grass64/etc/python/grass/script/core.py”, line 148, in start_command
return Popen(args, **popts)
File “/usr/lib/grass64/etc/python/grass/script/core.py”, line 53, in init
startupinfo, creationflags)
File “/usr/lib/python2.6/subprocess.py”, line 623, in init
errread, errwrite)
File “/usr/lib/python2.6/subprocess.py”, line 1141, in _execute_child
raise child_exception

OSError: [Errno 7] Argument list too long

Im pretty sure i’m missing something about how the Popen pipes are accessed between these two commands. Any suggestions would be most welcome.

Best,
Peter

Generally, this is the form that I use for python scripts and popen
(these examples are directly from working scripts of mine, but of
course you'll have to adapt them):

subprocess.Popen(
    "v.type input=%(a)s output=%(b)s type=point,centroid --overwrite" %
{'a':VECT,'b':'temp_centroid'},
    shell=True,
    stdout=subprocess.PIPE,).communicate()[0]

or if I don't need to capture data from a GRASS process I use this:

subprocess.call([
    "v.db.update",
    "map=%s" % vect,
    "layer=1","column=%s" % column,
    "value=%s" % value,
    "where=cat=%s" % cat,])

Chris

On 17 February 2011 20:36, Peter Tittmann <ptittmann@gmail.com> wrote:

Greetings,
I'm attempting to pipe the results from:
pts=sub.Popen('las2txt -i %s --parse xyz --keep-classes 2 --delimiter "|"
--stdout'%path, shell=True, stdout=sub.PIPE)

to the appropriate grass.?_command('r.in.xyz', etc...)
i've tried the following:
mkInRast=grass.feed_command("r.in.xyz", input=pts.communicate()[0],
output='tester', method='mean')
which results in:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/grass64/etc/python/grass/script/core.py", line 198, in
feed_command
return start_command(*args, **kwargs)
File "/usr/lib/grass64/etc/python/grass/script/core.py", line 148, in
start_command
return Popen(args, **popts)
File "/usr/lib/grass64/etc/python/grass/script/core.py", line 53, in
__init__
startupinfo, creationflags)
File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child
raise child_exception
OSError: [Errno 7] Argument list too long
Im pretty sure i'm missing something about how the Popen pipes are accessed
between these two commands. Any suggestions would be most welcome.
Best,
Peter

_______________________________________________
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

Hi,

see the GRASS Programmers' manual, python section:

  http://grass.osgeo.org/programming6/pythonlib.html

specifically grass.pipe_command().

See the python scripts in grass7/scripts/ for a large number
of examples.

Hamish