befuddled by os.exec functions

Avi Kak kak at purdue.edu
Thu Jul 22 23:50:55 EDT 2004


Hello:

 I'd be most grateful if someone could answer
 the following questions about the exec functions
 in the os module.

 1) How does one get one of the os.exec functions
    in Python to execute a shell script that
    includes some sort of a control structure in
    the shell script itself?

    For example, I can do the following in Perl

    $ENV{ACK_MSG} = "You said: ";
    exec('while a=a; do read MYINPUT; echo $ACK_MSG $MYINPUT; done');

    How can one use one of the os.exec functions
    in Python to do the same?  All of the os.exec
    functions require a pathname for the first
    argument, followed by well-defined arguments.
    But the above example does not break down
    into pathname and argument components.

 2) In the following example, I am mystified as
    to why the first element of the list in the
    second argument has to be ignored.  If it is
    going to be ignored anyway, why does it need
    to be supplied at all?  The following call
    does the same regardless of what one has in the
    first element of the second-arg list.

     os.execvp( 'ls', ['ls', '-al'] )

 Thanks.

 Avi Kak
 kak at purdue.edu




More information about the Python-list mailing list