[Tutor] missing first argument on subprocess.Popen w/ executable

A.T.Hofkamp a.t.hofkamp at tue.nl
Fri May 29 11:21:02 CEST 2009


Lie Ryan wrote:
> I'm wondering whether I have misunderstood the documentation or this is
> a bug in either the documentation or the python:
> 
> Python 2.5.4 (r254:67916, May 18 2009, 20:53:31)
> [GCC 4.3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import subprocess
>>>> subprocess.Popen(['a', 'b', 'c', 'd'], executable='echo')
> <subprocess.Popen object at 0x7fdf7bb2bd50>
> b c d
> 
> shouldn't the output be
> a b c d
> 
> where has the first argument (a) gone to?

Under Unix, it is the displayed executable name eg in 'ps':

 >>> import subprocess
 >>> subprocess.Popen(['60', '60'], executable='/bin/sleep')
<subprocess.Popen object at 0xb7ee0e6c>


While it is running, 'ps' lists

USER       PID %CPU %MEM  VSZ  RSS TTY      STAT START   TIME COMMAND
user     26056  0.1  0.0  8140 3480 pts/11   S+   11:13   0:00 python
user     26059  0.0  0.0  5796  560 pts/11   S+   11:14   0:00 60 60

> Normally the first argument in arg is the executable name, however we
> may also specify it as executable argument instead; but what's the
> rationale for zapping the first argument when executable is present?

It is still the name of the executable, the value is just not used for 
searching the program, rather just displayed.

> Or is it because I'm using a (rather) old version of python (the default
> python from Gentoo amd64)

Nope, it is feature of the OS. No way around it unless you patch the kernel.



Albert



More information about the Tutor mailing list