without shell

Grant Edwards grante at visi.com
Fri Jun 10 13:43:53 EDT 2005


On 2005-06-10, Donn Cave <donn at u.washington.edu> wrote:
> In article <11aj9d3fga9or8b at corp.supernews.com>,
>  Grant Edwards <grante at visi.com> wrote:
>
>> On 2005-06-10, Mage <mage at mage.hu> wrote:
>> 
>> >>py> file_list = os.popen("ls").read()
>> >>
>> >>Stores the output of ls into file_list.
>> >>
>> > These commands invoke shell indeed.
>> 
>> Under Unix, popen will not invoke a shell if it's passed a
>> sequence rather than a single string.
>
> I suspect you're thinking of the popen2 functions.

According to the current module reference, that's the behavior
of the os.popen*() functions:

http://docs.python.org/lib/os-newstreams.html#os-newstreams

> On UNIX, os.popen is posix.popen, is a simple wrapper around
> the C library popen.  It always invokes the shell.

Not according the the docs:

  Also, for each of these variants, on Unix, cmd may be a
  sequence, in which case arguments will be passed directly to
  the program without shell intervention (as with os.spawnv()).
  If cmd is a string it will be passed to the shell (as with
  os.system()).

It's not exactly clear what "these variants" refer to, but I
read it as referring to all of the the os.popen functions.

Perhaps it only refers to os.popen[234]?
  
> The no-shell alternatives are spawnv (instead of system) and
> the popen2 family (given a sequence of strings.)
>
>    Donn Cave, donn at u.washington.edu

-- 
Grant Edwards                   grante             Yow!  FIRST, I'm covering
                                  at               you with OLIVE OIL and
                               visi.com            PRUNE WHIP!!



More information about the Python-list mailing list