conversing with the shell

Fernando Pérez fperez528 at
Sun Nov 18 14:51:31 CET 2001

Michaell Taylor wrote:
> Problem is of course the SOMECOMMAND lines.  I need to query the shell for
> input and then read that input in as a variable.  I could use the shell
> commands to redirect the output to a file and then read the file with
> python, but this seems like a waste.

copied verbatim from my 'tools' module.

strip it down to output = commands.getoutput(cmd)
if performance is critical.

def bq(cmd,verbose=0,debug=0,head=''):
    """Dummy substitute for perl's backquotes.
    Executes a command and returns the output.

    if verbose or debug: print head+cmd
    if not debug:
        output = commands.getoutput(cmd)
        return output

More information about the Python-list mailing list