Shell-like functionality in Python

Oren Tirosh oren at hishome.net
Sat Jun 29 11:24:48 EDT 2002


Check out http://www.tothink.com/python/shell

It's still in a pretty early state but already provides a very convenient 
syntax for flexible execution of external commands from Python.

External commands appear as virtual methods of an object called 'cmd'.

Example:
Python 2.2 (#1, Jan 30 2002, 23:44:31)
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-98)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from shell.all import *
>>> cmd.ls()
all.py  command.py  __init__.py

It supports output redirection in the form of iterable commands:

>>> for x in cmd.ls['-l']:
...   print 'line:', x
...
line: total 20
line: -rw-rw-r--    1 oren     oren          216 Jun 27 20:49 all.py
line: -rw-rw-r--    1 oren     oren         8259 Jun 27 20:53 command.py
line: -rw-rw-r--    1 oren     oren          136 Jun 27 20:49 __init__.py

Passing the output of one command as arguments to another:

>>> cmd.chmod('+r', cmd.find['.', '-name', '*.html'])

And some other nifty features.

	Oren






More information about the Python-list mailing list