eine Funktion zu schreiben versucht, das die Ausgabe eines Shell-Befehl liest, bevor sie eine Entscheidung .. Zum Beispiel:Python Aufruf-Shell-Befehl und Antwort überprüfen
6 def getCreds():
7 global access_key, secret_key, yourName
8 access_key = raw_input("Enter Access Key: ")
9 secret_key = raw_input("Enter Secret Key: ")
10 infoCorrect = raw_input('Is this information correct? (y or n)')
11 if infoCorrect.lower() == "yes" or infoCorrect.lower() =="y":
12 call (["./somecommand -u %s -p %s -flags" % (access_key, secret_key) + tfdir],shell=True)
13 else:
Der Ausgang des Shell-Befehl ist entweder
"You have successfully logged in"
or
"you cannot log in"
So weiß ich nicht, die richtige Syntax zu gehen:
if response = "You have successfully logged in" :
(some action)
elif:
(some action)
Wie lese ich die Antwort?
Danke!
Wenn Sie dies regelmäßig tun, gibt es Convenience Wrapper zur Verfügung. Einer von ihnen: https://github.com/Chiel92/python-shellout (Disclaimer: Ich schrieb es) –
@chowpay, ist Ihr Problem gelöst? – Shasha99