Re: [grass-addons] r509 - trunk/grassaddons/gui/gui_modules

3 messages Options
Embed this post
Permalink
Michael Barton

Re: [grass-addons] r509 - trunk/grassaddons/gui/gui_modules

Reply Threaded More More options
Print post
Permalink
Daniel,


Should we start going through and switching instances of os.system to
os.execvp? 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)

What about os.popen and Popen?

Finally, how do we return the properly built command from buildCmd to put
into os.execvp?

thanks

Michael


On 4/15/07 11:00 PM, "[hidden email]" <[hidden email]> wrote:

> Log:
> - better test task: use with 'test' as the grass command
> - now cmdPanel may be queried by (i) buildCmd, which returns an array of
> arguments and (ii) createCmd, which is the usual cmdline string. This allows
> for both system-style use (with the usual quote madness), and a saner
> execve-style command launch.

__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton


_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Martin Landa

Re: Re: [grass-addons] r509 - trunk/grassaddons/gui/gui_modules

Reply Threaded More More options
Print post
Permalink
Hi,

2007/4/16, Michael Barton <[hidden email]>:

> Should we start going through and switching instances of os.system to
> os.execvp? 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)
>
> What about os.popen and Popen?
>
> Finally, how do we return the properly built command from buildCmd to put
> into os.execvp?

Please take look at cmd package.

Martin

>
> thanks
>
> Michael
>
>
> On 4/15/07 11:00 PM, "[hidden email]" <[hidden email]> wrote:
>
> > Log:
> > - better test task: use with 'test' as the grass command
> > - now cmdPanel may be queried by (i) buildCmd, which returns an array of
> > arguments and (ii) createCmd, which is the usual cmdline string. This allows
> > for both system-style use (with the usual quote madness), and a saner
> > execve-style command launch.
>
> __________________________________________
> Michael Barton, Professor of Anthropology
> School of Human Evolution & Social Change
> Center for Social Dynamics & Complexity
> Arizona State University
>
> phone: 480-965-6213
> fax: 480-965-7671
> www: http://www.public.asu.edu/~cmbarton
>
>
> _______________________________________________
> grassgui mailing list
> [hidden email]
> http://grass.itc.it/mailman/listinfo/grassgui
>


--
Martin Landa <[hidden email]> * http://gama.fsv.cvut.cz/~landa *

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui
Glynn Clements

Re: Re: [grass-addons] r509 - trunk/grassaddons/gui/gui_modules

Reply Threaded More More options
Print post
Permalink
In reply to this post by Michael Barton

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 <[hidden email]>

_______________________________________________
grassgui mailing list
[hidden email]
http://grass.itc.it/mailman/listinfo/grassgui