[GRASS-user] Running an external executable file from a Python Script

Glynn Clements glynn at gclements.plus.com
Thu Mar 10 10:21:55 EST 2011


António Rocha wrote:

> My question is, when I'm running a GRASS python Script what is my active 
> folder in order to place there my Parameter file? Or, is there any way 
> to change my "active folder" while I'm running GRASS python Script?

By "active folder", I presume that you're referring to the current
directory (aka working directory, current working directory or CWD). 
This is inherited from the calling process; e.g. if you run a script
from a shell, the script's current directory will be the shell's
current directory.

When executing a command via subprocess.Popen(), you can specify its
current directory via the cwd= parameter. The grass.Popen() and
grass.call() functions accept this parameter, as do all of the
grass.*_command() functions for running GRASS modules.

You can change the current directory for the current process using
os.chdir(), but that should normally be avoided, as any relative
filenames will then be interpreted relative to the new current
directory, whereas the user probably intended them to be relative to
the initial current directory.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list