a sub process problem.

Uwe Hoffmann nospam at nospam.de
Sun May 27 06:30:01 EDT 2001


Rajarshi Guha wrote:
> 
> i,
>   I was writing a script to search my mail archives. After doing the search
> I'd like to start Pine from the script and view the results. In addition
> after the
> exit of Pine I want the script to carry on - ie the script should wait until
> the pine process finishes. I've tried using the popen2 class but I get the
> following error:
> 
> Traceback (most recent call last):
>   File "/home/rajarshi/src/misc/py/ptest.py", line 153, in ?
>     print p.poll()
> AttributeError: 'tuple' object has no attribute 'poll'
> 
> ,where p = os.popen4("pine")

instead use p=popen2.Popen4("pine")

http://www.python.org/doc/current/lib/module-popen2.html
the Popen4 objects created by popen4 
(maybe the term factory function is misleading here, i'm not sure) 
are used internally only.

from popen2.py library module
...
def popen4(cmd, bufsize=-1, mode='t'):
    """Execute the shell command 'cmd' in a sub-process.  If 'bufsize'
is
    specified, it sets the buffer size for the I/O pipes.  The file
objects
    (child_stdout_stderr, child_stdin) are returned."""
    inst = Popen4(cmd, bufsize)
    return inst.fromchild, inst.tochild
...

> 
> But the docs say that instances of popen2 and peopn4 have the methods poll()
> and wait().  I also tried os.spawn(os.P_WAIT,"pine") but then the the
> program just carries on and no pine comes up.
> 
> Could somebody please tell me where I'm going wrong and how I could solve
> this problem.
> 
> PS. I'm doing all this under Linux and Python 2.1
> TIA,
> 
> --
> -------------------------------------------------------------
> Rajarshi Guha
> 
> email: rajarshi at presidency.com
> web: http:/www.psynet.net/jijog



More information about the Python-list mailing list