[GRASS-user] Using pipes in python scripts
Glynn Clements
glynn at gclements.plus.com
Fri Jul 2 03:59:39 EDT 2010
Ned Horning wrote:
> I'm making progress translating my shell script to Python but ran into
> another stumbling block. I would like to convert the following shell
> script command to the python scrip:
> --
> v.out.ascii $randomName fs=' ' | r.what input=$resampName> $pointTableName
> --
>
> I tried various combinations of grass.pipe_command and
> grass.feed_command but haven't been able to get it to work.
Using pipe_command() and feed_command() will give you two pipes (one
each), but you only want one. Use start_command():
outf = file(pointTableName, 'w')
p1 = grass.pipe_command('v.out.ascii',
input = randomName,
fs = ' ')
p2 = grass.start_command('r.what',
input = resampName,
stdin = p1.stdout,
stdout = outf)
outf.close()
p1.stdout.close()
p1.wait()
p2.wait()
start_command() is the most general function; all of the others
(except exec_command()) end up invoking start_command().
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list