how to start a new process while the other ist running on

Donn Cave donn at
Wed Dec 22 19:03:47 CET 2004

In article <cqbh6m$ttc$1 at>, Erik Geiger <Erik.geiger at> 
> Fredrik Lundh schrieb:
> > Erik Geiger wrote:
> > 
> [...]
> >> How to start a shell script without waiting for the exit of that shell
> >> script? It shall start the shell script and immediately execute the next
> >> python command.
> > 
> > if you have Python 2.4, you can use the subprocess module:
> > 
> >
> > 
> > see the spawn(P_NOWAIT) example for how to use it in your
> > case:
> > 
> >
> Thats what I've tried, but it did not work. Maybe it's because I want to
> start something like su -c '/path/to/skript $parameter1 $parameter2' user
> I don't understand the syntax of spawn os.spawnlp(os.P_NOWAIT, "/path/to
> script", "the script again?", "the args for the script?")

Unfortunately this particular case kind of dilutes the advantages
of spawnv.  In the common case, parameter1 et al. would be submitted
directly as the parameter list.  I believe it may be clearer to start
with to think about the spawnv() function -
   os.spawnv(os.P_NOWAIT, path, [cmdname, parameter1, parameter2])

If one of the parameters is itself another command, then of course
it has to be rendered as a string
   os.spawnv(os.P_NOWAIT, '/bin/su', ['su', '-c', '%s %s %s' % (cmd,
      parameter1, parameter2)])
so you have almost as much work to scan the parameters for shell
metacharacters as you would have with system().

   Donn Cave, donn at

More information about the Python-list mailing list