How to disable spawnv's child process output messages

Donn Cave donn at u.washington.edu
Wed Jul 23 15:09:56 EDT 2003


In article <db3b6d24.0307231030.7dfa1b70 at posting.google.com>,
 nushin2 at yahoo.com (nushin) wrote:

> Hi Donn. Thanks for your response. Yes, in this case my parent process
> is hello_moon.py that is spwaning the child process, hello_earth.py. I
> am simply printing a hello world from each process and do not wish to
> see any output messages from the child process, and i *have to* see
> the output from the parent process, hello_moon.py
> 
> Could you please elaborate more on how i can use dup2( ) to disable
> the output of the child process spawned by spawnv( ) API?

It can't be done - as I said, spawnv can't do any kind of redirection,
and that is what it would take.

   Donn Cave, donn at u.washington.edu
-----------------------------------
> "Donn Cave" <donn at drizzle.com> wrote in message 
> news:<1058938603.850678 at yasure>...
> > Quoth nushin2 at yahoo.com (nushin):
> > | I have a program called hello_earth.py that is spawned by
> > | hello_moon.py, using spawnv( ) API as:
> > |
> > | os.spawnv(os.P_NOWAIT,'/usr/bin/python',('python','hello_earth.py'),('>/de
> > | v/null
> > | &'))
> > |
> > | I do not wish to see any output messages from the hello_earth.py when
> > | it is launched by its parent process and i do wish to see *only* the
> > | output messages from the parent process in the shell. Is Python
> > | capable to so such a thing?
> > 
> > What is the parent process in the shell?  You mean the one that calls
> > spawnv()?  If so - yes, Python can do that.  But not so easily.  You
> > can look at how spawnv is implemented (it's in Python), and read up
> > on the dup2 function (man 2 dup2) to see what's needed.  spawnv can't
> > do any kind of redirection.  I think I posted an example here a couple
> > weeks ago.
> > 
> > Or you can use the shell, more or less the way you were going but you
> > never invoked it -
> >   os.spawnv(os.P_NOWAIT, '/bin/sh', ['sh', '-c', 'python hello_earth.py > 
> >   /dev/null'])
> > 
> > which is really about the same as
> >   os.system('python hello_earth.py > /dev/null &')
> > 
> > 	Donn Cave, donn at drizzle.com




More information about the Python-list mailing list