[GRASS-dev] grass and python

Glynn Clements glynn at gclements.plus.com
Mon Aug 14 04:14:21 EDT 2006


David Finlayson wrote:

> The Python interpreter is interactive, but it is not a general purpose
> shell. You would need to wrap external programs in an os.system or
> os.popencall. One attractive way of getting around this is to pre-wrap
> each program
> in a python object. For example:
> 
> class Display:
> 
>     def rast(self, rastername):
>         os.system("d.rast %s" % rastername)

What does os.system() do on Windows? If it passes the command directly
to the underlying OS function (e.g. CreateProcess()), this will fail
when applied to a script, as Windows won't figure out that it needs to
run the script via an interpreter.

On Unix, if you call execve() (directly or indirectly) on a script
(any executable file beginning with "#!"), the kernel will read the
name of the interpreter from the #! line and execute it, passing the
path to the script as an argument.

AFAIK, Windows doesn't have any such functionality; it relies upon
extensions to determine what to do with a file. Windows ports of bash
handle scripts by inspecting the "executable" themselves.

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




More information about the grass-dev mailing list