[Twisted-Python] How to emulate Python's getoutput function

Christopher Armstrong radeex at gmail.com
Fri Oct 7 23:40:03 EDT 2005

On 10/8/05, Drake Smith <drakesmith at adelphia.net> wrote:
> Is there a relatively simple way to emulate the following python function:
>    commands.getoutput ('ifconfig eth0 | grep inet'))
> I can get halfway there with:
>    utils.getProcessOutput ('/sbin/ifconfig', ['eth0'])
> but the trick to piping that output to another command such as grep is
> eluding me. Thank you.

make the command "sh", and the arguments ['-c', 'shell string']. Of
course, this means you're opening yourself up to shell insertion
attacks if you put any user-input into that shell string.

  Twisted   |  Christopher Armstrong: International Man of Twistery
   Radix    |    -- http://radix.twistedmatrix.com
            |  Release Manager, Twisted Project
  \\\V///   |    -- http://twistedmatrix.com
   |o O|    |

More information about the Twisted-Python mailing list