[FRPythoneers] Shell commands in interactive mode

Eric Brunson brunson at level3.net
Wed Jul 25 13:58:38 MDT 2001


I think the only way to get close to what you want to do would require
subclassing the parser and completely rewriting it since only keywords
can be used without parens, and only some of them.  It is, afterall, a
python shell expecting you to type python.

At the most, I might see enhancing the interactive mode to support
shell escapes using a "!" or similar, but beyond that you'd just be
rewriting bash.  It seems a bit odd that you'd need that much shell
functionality within the interpretter, I would just open another
window.

* cary miller (cmiller at math.cudenver.edu) [010725 13:34]:
> That will get you arbitrary shell commands but what I would like to have
> is completely transparent access to the shell without qoute marks or any
> python commands intervening.  It's probably a mad dream but fun to think
> about.  Here is another idea.
> 
> >>> sh cat foo | grep bar > baz.py
> for example.
> You precede the shell command with sh (an undeclared variable).
> You have code that looks for NameError: sh
> When such an error is found the rest of the line gets executed with the
> command module or something.
> I think it would work but it seems a bit fishy so I have not tried it.
> 
> cam
> 
> On Wed, 25 Jul 2001, Eric Brunson wrote:
> 
> >
> > Try reading about commands module and see if that does what you need
> > it to do.
> >
> > http://python.org/doc/current/lib/module-commands.html
> >
> > * cary miller (cmiller at math.cudenver.edu) [010725 13:06]:
> > > Hi
> > >
> > > 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
> > > type
> > > >>> ls
> > > or
> > > >>> pwd
> > > and get exactly what you would see if you typed the same in the shell.
> > >
> > > Problems:
> > >     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):
> > >         self.cmd=cmd
> > >     def __repr__(self):
> > >         eval('os.system(self.cmd)')
> > >         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
> > > http://www-math.cudenver.edu/~cmiller
> > >
> > > _______________________________________________
> > > 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
> >
> >
> >
> 
> -- 
> Cary Miller
> Math Deparment
> University of Colorado - Denver
> cmiller at math.cudenver.edu
> http://www-math.cudenver.edu/~cmiller
> 
> _______________________________________________
> 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 mailing list