spawnv

brueckd at tbye.com brueckd at tbye.com
Wed Aug 15 00:24:36 EDT 2001


On Wed, 15 Aug 2001, Olivier Scalbert wrote:

> On my Linux box, the following code does not start /usr/bin/gears:
>
> import os
> print os.spawnv(os.P_WAIT, "/usr/bin/gears", ())
>
> In fact it print 127 !
>
> but the following code starts /usr/bin/gears :
>
> import os
> os.system("/usr/bin/gears")
>
> Why ?

Hi Olivier,
The arguments you pass to the child process are C-style arguments, so the
first one needs to be the program name. Also, spawnv takes a list of
arguments to pass, so what you really want is:

print os.spawnv(os.P_WAIT, '/usr/bin/gears', ['gears'])

So if you wanted to pass an argument to gears then your list would
look like:

['gears',<your arg here>,...]

Another way is to use spawnl; you pass in a variable number of
arguments:

print os.spawnl(os.P_WAIT, '/usr/bin/gears', 'gears', ...other args...)

Note that the spawn functions return the process ID of the child process,
unless you use P_WAIT, in which case they return the return code of the
child process once it finally exits.

-Dave





More information about the Python-list mailing list