2016-03-21 10 views
-1

? python betiğine bash komutunu çalıştırın python betiğinde aşağıdaki komutu çalıştırmak için

echo "show stat" | socat unix-connect:/var/run/haproxy/admin.sock stdio | grep webservers,BACKEND | cut -d , -f8 

Bu

import subprocess 
var = subprocess.check_output(echo "show stat" | socat unix-connect:/var/run/haproxy/admin.sock stdio '| grep ' webservers,BACKEND' | cut -d , -f8', shell=True) 
var=int(var) 

çalıştı ama o çalışmıyor! Popen ile

+1

'var = subprocess.check_output (""" yankı "gösteri istatistik" | Unix-bağlamak SoCat: /var/run/haproxy/admin.sock stdio '| grep' webservers, BACKEND '| cut -d, -f8' "" ", shell = True)' –

+0

bu soruyu kontrol edin http://stackoverflow.com/questions/27911820/python-subprocess-with-quotes-and-pipe-grep –

+1

Bir dize, bir komut iletmeniz gerekmiyor. – asimoneau

cevap

0

deneyin:

from subprocess import Popen, PIPE 

p1 = Popen(["echo", "show stat"], stdout=PIPE) 
p2 = Popen(["socat", "unix-connect:/var/run/haproxy/admin.sock", "stdio"], stdin=p1.stdout) 
p3 = Popen(["grep", "webservers,BACKEND"], stdin=p2.stdout) 
p4 = Popen(["cut", "-d", ",", "-f8"], stdin=p3.stdout) 
İlgili konular