2017-03-29 3 views
0

Ich möchte eine Variable verwenden und es an die Shell-Befehlszeile weitergeben. Das Problem ist. Ich weiß nicht wie. Brauche Hilfe.Python 2.7 übergeben Variable in Subprozess-Befehlszeile

def gauti(): 
    imti=tekstas.get("1.0", "end-1c") 
    subprocess.call("grep -i 'imti' /var/log/syslog > logas.txt", shell=True) 

Statt ‚IMTI‘ Ich brauche eine Variable, die in Python-Programm geliefert werden würden in syslog-Datei durchsucht werden.

Antwort

0

Verwenden Zeichenfolge Formatierungs

subprocess.call("grep -i '{imti}' /var/log/syslog > logas.txt".format(imti=imti), 
       shell=True) 

oder Pass Array call Verfahren mit allen erforderlichen Teilen

logas = open('logas.txt', 'a+') 
subprocess.call(['grep', '-i', imti, '/var/log/syslog'], stdout=logas)