[FRPythoneers] Shell commands in interactive mode
brunson at level3.net
Wed Jul 25 13:12:26 MDT 2001
Try reading about commands module and see if that does what you need
it to do.
* cary miller (cmiller at math.cudenver.edu) [010725 13:06]:
> In tcl interactive mode you have access to shell commands like pwd and
> ls. I wanted python to do that and came up with the following. This
> code goes in pythonstartup. The nice thing about it is that you just
> >>> ls
> >>> pwd
> and get exactly what you would see if you typed the same in the shell.
> 1. Blank line after the output. The problem here is __repr__ is
> required to return a string. Is there any way around this?
> 2. Only works for one-word commands. Cannot pass options to ls,
> and cannot do this
> >>> cat foo.py
> Is there a way to do multiword shell commands??
> import os
> class ShellCommand:
> def __init__(self,cmd):
> def __repr__(self):
> return ''
> pwd = ShellCommand('pwd')
> ls = ShellCommand('ls')
> Here is the best I aan come up with for cat.
> def cat(file):
> for line in open(file).readlines():
> print line,
> Cary Miller
> Math Deparment
> University of Colorado - Denver
> cmiller at math.cudenver.edu
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers
Eric Brunson - brunson at level3.net - page-eric at level3.net
"When governments fear the people there is liberty. When the people
fear the government there is tyranny." - Thomas Jefferson
More information about the FRPythoneers