[FRPythoneers] Shell commands in interactive mode

Eric Brunson brunson at level3.net
Wed Jul 25 15:22:35 MDT 2001


* cary miller (cmiller at math.cudenver.edu) [010725 15:05]:
> On Wed, 25 Jul 2001, Eric Brunson wrote:
> >
> > 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.
> 
> You are right I do not need it.  But I thought of it, did not know haw to
> do it and kept thinking about it.  Is this what you mean by shell escape?
> 
> class Shell:
>     def __repr__(self):
>         eval('os.system(raw_input())')
>         return ''
> 
> sh = Shell()
> 

Woah!  That's pretty cool.

The usual idiom is '! command' but that's an excellent workaround.

I'd probably use the following to get around the eval (I'm not sure
how expensive it is, but it seems a bit superflous to me, though I'm
starting to sound like Randall Schwartz with his annoying Useless Use
of a Cat Award).

class Shell:
    def __repr__(self):
        return( commands.getoutput( raw_input() ) )


I think I'll have to toss that into my .pythonrc  :-)

-- 
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