[Python-Dev] popen behavior
Kevin Butler
kbutler@campuspipeline.com
Tue, 18 Jun 2002 18:37:06 -0600
Martin v. Loewis wrote:
> Kevin Butler <kbutler@campuspipeline.com> writes:
>
>>- Should we maintain the os.popen & popen2.popen dual exposure with
>>their different argument & return value orders?
>
> Certainly. Any change to that will break existing applications.
Actually, it would just "fail to enable existing applications that currently
don't work on Jython". :-) But if one or the other form is or will be
deprecated in CPython, I probably wouldn't expose it in Jython at this point
(TMTOWTDI, etc.)
>>- Should we maintain the different behavior for lists of arguments vs
>>strings? (it does not appear to be documented)
>
> If you propose to extend argument processing for one of the functions
> so that passing the additional arguments in current releases produces
> an exception - then adding this extension would be desirable if that
> adds consistency.
I'm not sure what you meant here.
The inconsistency is as follows (Python output below):
On both (all?) platforms:
popen*( "cmd arg arg" ) executes cmd in a subshell
popen( ["cmd", "arg", "arg"] ) fails
In win32:
popen[234]( ["cmd", "arg", "arg"] ) fails
In posix:
popen[234]( ["cmd", "arg", "arg"] ) runs cmd w/o a subshell
I consider the posix behavior more useful (especially on Java where we can't
always determine a useful shell for a platform), but where it isn't documented
and isn't supported in win32, I wasn't sure if I should support it.
I think it would also be useful and more consistent to allow popen() to accept
an args list, which is currently not supported on either platform. Should I
allow this for Java?
Should I spend time to make the Win32 functions accept the args lists?
kb
Python 2.1.1 (#1, Aug 25 2001, 04:19:08)
[GCC 3.0.1] on sunos5
Type "copyright", "credits" or "license" for more information.
>>> from os import popen, popen2
>>> out = popen( "echo $USER" )
>>> out.read()
'kbutler\n'
>>> out = popen( ["echo", "$USER"] )
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: popen() argument 1 must be string, not list
>>> in_, out = popen2( ["echo", "$USER"] )
>>> out.read()
'$USER\n'
>>> in_, out = popen2( "echo $USER" )
>>> out.read()
'kbutler\n'
>>>
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from os import popen, popen2
>>> out = popen( "echo %USERNAME%" )
>>> out.read()
'kbutler\n'
>>> out = popen( ["echo", "%USERNAME%"] )
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: popen() argument 1 must be string, not list
>>> in_, out = popen2( ["echo", "%USERNAME%"] )
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: popen2() argument 1 must be string, not list
>>> in_, out = popen2( "echo %USERNAME%" )
>>> out.read()
'kbutler\n'
>>>