spawnv

Olivier Scalbert olivier.scalbert at algosyn.com
Wed Aug 15 09:11:22 CEST 2001


brueckd at tbye.com wrote:

> 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

Thanks, it works !

olivier




More information about the Python-list mailing list