[Python-3000] os.popen versus subprocess.Popen

Guido van Rossum guido at python.org
Tue Apr 22 17:39:47 CEST 2008


I need to retract this. os.popen() has a 'mode' flag that indicates
reading or writing but also specifies text vs. binary. So
os.popen(..., 'r') should return a text stream, while os.popen(...,
'rb') should return a binary stream.

The subprocess module has similar options, though the default is
geared more towards binary.

I still think os.popen() should be reimplemented on top of subprocess,
and add the same optional flags as the open() function has grown to
indicate encoding and buffering.

I think the more complex variants (popen2, popen3, popen4, ...?)
should probably go away, since it's easy enough to do what they do
using the subprocess module, and there were some serious API design
mistakes there (confusing reversal of input and output in some cases).

--Guido

On Mon, Apr 21, 2008 at 10:30 AM, Guido van Rossum <guido at python.org> wrote:
> IMO os.popen() is wrong here.
>
>
>
>  On Sat, Apr 12, 2008 at 4:33 PM, Tim Heaney <theaney at gmail.com> wrote:
>  > In Python 3.0, it seems that os.popen yields a string, whereas
>  >  subprocess.Popen yields bytes
>  >
>  >   $ ./python
>  >   Python 3.0a4 (r30a4:62119, Apr 12 2008, 18:15:16)
>  >   [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
>  >   Type "help", "copyright", "credits" or "license" for more information.
>  >   >>> import os, subprocess
>  >   >>> os.popen('date').readline()
>  >   'Sat Apr 12 19:08:05 EDT 2008\n'
>  >   >>> subprocess.Popen(['date'], stdout=subprocess.PIPE).communicate()[0]
>  >   b'Sat Apr 12 19:08:13 EDT 2008\n'
>  >
>  >  Is this intentional? If so, why should I expect this? Thanks!
>  >
>  >  Tim
>  >  _______________________________________________
>  >  Python-3000 mailing list
>  >  Python-3000 at python.org
>  >  http://mail.python.org/mailman/listinfo/python-3000
>  >  Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>  >
>
>
>
>  --
>  --Guido van Rossum (home page: http://www.python.org/~guido/)
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list