Recupérer le code retour shell pour afficher un message

xunil2003 Messages postés 766 Date d'inscription   Statut Membre Dernière intervention   -  
xunil2003 Messages postés 766 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,

je suis sur un vieux PC avec python 2.7.6

Ici je récupère le retour shel d'une commande bash d'un api
sortie=os.popen(CMD2, "r")
print sortie.read()

j'essaie de récupérer le code du retour, ici le chiffre 200
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 17 Oct 2019 15:09:06 GMT
Transfer-Encoding: chunked
Connection: keep-alive

None

En fonction du chiffre 200, 400 etc.. je doit afficher un message avec tkMessageBox.

Auriez-vous une solution ?
Merci d'avance pour vos conseil est avis

Configuration: Linux / Firefox 69.0

1 réponse

  1. xunil2003 Messages postés 766 Date d'inscription   Statut Membre Dernière intervention   14
     
    re,

    Pour l'instant j'ai trouvé cette solution
    from subprocess import check_output
    chaine = check_output(CMD3+' | grep 200', shell=True)
    print(chaine[9:12])

    ce qui retour
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
    Dload Upload Total Spent Left Speed
    0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
    HTTP/1.1 200 OK

    200
    None
    0