classification
Title: os.popen with invalid mode differs on Windows and POSIX
Type: enhancement Stage: test needed
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, ajaksu2, amaury.forgeotdarc, gaul, georg.brandl, georg.brandl, techtonik
Priority: low Keywords:

Created on 2003-09-01 12:34 by gaul, last changed 2010-08-18 18:17 by BreamoreBoy. This issue is now closed.

Messages (6)
msg61120 - (view) Author: Andrew Gaul (gaul) Date: 2003-09-01 12:34
On Windows, os.popen with an invalid mode throw a
ValueError and on POSIX systems it throws an OSError.

Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32
bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for
more information.
>>> import os
>>> os.popen('dir', '')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: popen() arg 2 must be 'r' or 'w'

Python 2.3 (#167, Sep  1 2003, 06:38:18)
[GCC 3.0.4] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import os
>>> os.popen('ls', '')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
OSError: [Errno 22] Invalid argument

Additionally, the ValueError message is incorrect; arg
2 can be 'r', 'rb', 'rt', 'w', 'wb', or 'wt'.
msg61121 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-06-05 17:26
Logged In: YES 
user_id=1188172

Should the exceptions be synchronized?
msg81866 - (view) Author: Daniel Diniz (ajaksu2) (Python triager) Date: 2009-02-13 03:37
This snippet still raises 'OSError: [Errno 22] ...' in Linux:

import os
os.popen('ls', '')

Can anyone do a quick check on Windows?
msg82041 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-02-14 12:55
On Windows:

>>> os.popen("cmd", "")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: popen() arg 2 must be 'r' or 'w'

Windows has a specific implementation of os.popen, which does validate 
the mode. Whereas on POSIX platforms, the parameters are passed as is to 
the popen() function.
I'd call this an "implementation detail", and the exact exception is not 
important IMO.
msg88955 - (view) Author: anatoly techtonik (techtonik) Date: 2009-06-05 17:43
I can confirm this but, but os.popen() is deprecated in 2.6 hence there
is no point in fixing generated exception even though in a language that
claims to be cross-platform exceptions should be unified.

I would add os.popen to keywords list for future reference and close
this bug as "won't fix". There are many other bugs about os.popen on
windows platform and people would be interested to know exactly why
subprocess should be used.
msg114261 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-18 18:17
Closed as os.popen deprecated in favour of subprocess.popen.
History
Date User Action Args
2010-08-18 18:17:34BreamoreBoysetstatus: open -> closed

nosy: + BreamoreBoy
messages: + msg114261

resolution: wont fix
2009-06-05 17:43:46techtoniksetnosy: + techtonik
messages: + msg88955
2009-02-14 12:55:58amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg82041
2009-02-13 03:37:15ajaksu2setpriority: normal -> low
nosy: + ajaksu2, georg.brandl
stage: test needed
messages: + msg81866
versions: + Python 2.7
2003-09-01 12:34:47gaulcreate