Search code examples
pythontwistedtwisted.internet

twisted run local shell commands with pipeline


In twisted, getProcessOutput method could get 'ps' shell command ouput by using getProcessOutupt('ps', 'aux') and return a defer.

my question is how to run command like "ps aux | grep 'some keyword' | awk '{...}'" in getProcessOutput. for example getProcessOutput("ps aux | grep 'some keyword' | awk '{...}'").

any suggestions would be appreciated.


Solution

  • use getProcessOutput('/bin/sh', ('-c', cmd)). cmd is your shell command. try it :-)