Ksh-ish functionality on Unix systems

Greg Weeks weeks at vitus.scs.agilent.com
Thu Sep 20 17:44:57 EDT 2001


My operating system is Unix.  One decision that I would like to eliminate
when I"m faced with a small programming task is: Ksh or Python?  I'd like
to just reach for Python.

Here are some things that Ksh does conveniently:

    <  >  >>  2>  2>>  2>&1		# REDIRECTION
    &					# BACKGROUND
    |					# PIPING
    $() or ``				# CAPTURING STDOUT

And here is what I find in Python:

  LOW LEVEL:
    os:  open pipe dup2 close fork execv waitpid
  HIGHER LEVEL:
    os:        system
    os:        popen
    commands:  getstatusoutput
    popen2:    *

The low-level support is far too verbose for casual use.  The higher-level
stuff seems incomplete.  However, the higher-level stuff becomes a lot more
complete if the command arguments are passed to, say, /bin/sh on Unix
systems.  In that case, os.system and getstatusoutput capture the above Ksh
functionality, and os.popen and popen2.* are bonuses.

So: Is it a reasonable approach as a Unix user to rely on the fact that the
os.system and getstatusoutput commands are passed to a shell?

Or is that tacky?  If that *is* tacky, is there a *convenient* alternative?


Regards,
Greg


PS: Wishfully thinking, I tried re-assigning sys.output.  But that rebinds
the stream, not the file-descriptor.



More information about the Python-list mailing list