This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.popen2 and os.popen3 in python 2.6 incompatible with os.popen* in python 2.5
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pjenvey Nosy List: amaury.forgeotdarc, exarkun, jahakala, maxb, pitrou, pjenvey
Priority: high Keywords: patch

Created on 2009-02-20 09:14 by jahakala, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
os-popen.diff jahakala, 2009-02-20 11:12 Lib/os.py fix against release26-maint
os-popen-list.patch exarkun, 2009-08-27 16:43 Unit tests for os.popen2, os.popen3, and os.popen4 with a list instead of a string
subprocess-conversion-doc.patch exarkun, 2009-09-05 15:12 update the docs for converting from os.popen* to subprocess.Popen
subprocess-conversion-doc2.patch pjenvey, 2009-09-29 17:17
Messages (11)
msg82523 - (view) Author: Jani Hakala (jahakala) Date: 2009-02-20 09:14
The implementation in python 2.6 expects the cmd argument to be a string. 
The documentation - help(os.popen3) - states that the cmd argument can
be a sequence on Unix.

This difference may cause programs that work with python 2.5 to fail
with python 2.6

I have tested the patch attached with one of my scripts that failed with
python 2.6 and the fix appears to work.
msg82567 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-02-21 14:24
Adding a couple of unit tests would be nice.
msg90259 - (view) Author: Max Bowsher (maxb) Date: 2009-07-08 08:15
With or without tests, this is a regression from Python 2.5 - shouldn't
something be done about that?
msg90266 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-07-08 13:22
The test is the proof the the regression, and shows the change in
behavior and the purpose of the development.
There happens to be a test for os.popen3 (in Lib/test/test_popen2.py)
which passes a list; this one at least passes.

os.popen3() accepts a sequence, except that since 2.6, the first item is
the whole command string, and additional items are treated as additional
shell arguments!

Your patch is correct. A unit test could be:
    w, r, e = os.popen3(['echo', 'hello'])
    assert r.read() == 'hello\n'
And should be disabled on non-posix platforms.
msg92008 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-08-27 16:44
Attached os-popen-list.patch which includes all of the earlier
os-popen.diff and adds tests which fail without this patch and pass with
it.  They also pass on Python 2.5.  The patch is against the Python 2.6
maintenance branch, but presumably it should be applied to trunk as well.
msg92227 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) Date: 2009-09-04 02:37
The subprocess docs (in Doc/library/subprocess.rst and the module itself) 
need to also reflect this change
msg92228 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-09-04 02:51
Hey Philip,

I'm not sure I follow.  The patch only changes the os module, not the
subprocess module.  What subprocess documentation do you think needs to
be updated?
msg92229 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) Date: 2009-09-04 02:59
Sorry, I meant the docs describing how to convert os.popen* calls to 
subprocess calls. They assume the shell arg is always True regardless of 
the cmd arg type. Those docs are probably the original source of this bug
msg92279 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2009-09-05 15:13
Ah, thanks for the clarification, Philip.  I've attached another patch
updating those docs.
msg93304 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) Date: 2009-09-29 17:17
Here's the doc change with a lil more clarification, and I've also applied 
it to the module's own docs
msg93318 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) Date: 2009-09-29 19:19
applied in r75143/r75144, in time for 2.6.3. thanks!
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49579
2009-09-29 19:19:57pjenveysetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg93318
2009-09-29 18:49:15barrysetkeywords: - needs review
assignee: pjenvey
resolution: accepted
2009-09-29 17:17:27pjenveysetfiles: + subprocess-conversion-doc2.patch

messages: + msg93304
2009-09-05 15:13:17exarkunsetmessages: + msg92279
2009-09-05 15:12:49exarkunsetfiles: + subprocess-conversion-doc.patch
2009-09-04 02:59:43pjenveysetmessages: + msg92229
2009-09-04 02:51:17exarkunsetmessages: + msg92228
2009-09-04 02:37:33pjenveysetnosy: + pjenvey
messages: + msg92227
2009-08-27 16:44:57exarkunsetnosy: + exarkun
messages: + msg92008
2009-08-27 16:43:13exarkunsetfiles: + os-popen-list.patch
2009-07-08 13:22:05amaury.forgeotdarcsetkeywords: + needs review
nosy: + amaury.forgeotdarc
messages: + msg90266

2009-07-08 08:15:09maxbsetmessages: + msg90259
2009-07-08 08:12:41maxbsetnosy: + maxb
2009-02-21 14:24:44pitrousetpriority: high
nosy: + pitrou
messages: + msg82567
versions: + Python 2.7
2009-02-20 11:13:01jahakalasetfiles: - os-popen.diff
2009-02-20 11:12:38jahakalasetfiles: + os-popen.diff
2009-02-20 09:35:11jahakalasettype: behavior
2009-02-20 09:14:02jahakalacreate