[GRASSGUI] Re: [grass-addons] r509 -
trunk/grassaddons/gui/gui_modules
Glynn Clements
glynn at gclements.plus.com
Mon Apr 16 10:11:39 EDT 2007
Michael Barton wrote:
> Should we start going through and switching instances of os.system to
> os.execvp?
os.execvp replaces the current program; it never returns.
If you want the semantics of os.system (execute a program as a child
process) but without using a shell, use the os.spawn* functions, or
the Popen library.
> What is the correct syntax for something like this...
>
> vcmd = "v.what -a map=%s east_north=%f,%f distance=%f" % \
> (vectstr, float(x), float(y), qdist)
>
> os.system(vcmd)
>
> Is it...?
>
> vcmd = ['v.what', '-a', 'map='+vectstr, 'east_north=%f,%f' % ( float(x),
> float(y)), 'distance='+qdist]
>
> os.execvp(vcmd)
vcmd = ["v.what", "-a", "map="+vectstr, "east_north=%f,%f" % (float(x), float(y)), "distance="+qdist]
os.spawnvp(os.P_WAIT, "v.what", vcmd)
Note that the command appears a both a separate argument and as the
first entry in the argv array.
> What about os.popen
os.popen returns a handle for the child's stdin/stdout, and executes
the command in the background.
Roughly, spawn* are analogous to Tcl's exec, while os.popen is
analogous to Tcl's "open |...".
However, os.popen only allows the command to be passed as list of
separate arguments on Unix. On Windows, the command has to be a single
string which is passed to the command interpreter (cmd.exe or
command.com).
> and Popen?
Popen is probably the way to go. It appears to support all of the
functionality of os.{system,spawn*,popen*} and popen2.*, and does so
on both Unix and Windows.
> Finally, how do we return the properly built command from buildCmd to put
> into os.execvp?
Can you elaborate?
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-gui
mailing list