Bonjour
J’essaie d'obtenir le code erreur en sortie d'un batch pour le remonter à la console WAPT.
Je pars d'un modèle (template) vide où j'ai ajouté mon script et modifié le setup.py.
*Voici le contenu du fichier bat de test*
@ECHO OFF REM On teste si un fichier quelconque existe. IF EXIST "C:\essai.txt" ( REM Permet la sortie du script avec un code erreur. REM Ici, si le fichier existe on sort avec le code 0. exit /b 0 ) ELSE ( REM Sinon le code 1. exit /b 1 )
*Ci-dessous partie du setup.py que j'ai modifié en stipulant les codes retour.*
def install(): run("Batch.bat",accept_returncodes=[0,1])
En fait, j'ai l'impression que la console dit que l'installation est OK juste car il a exécuté le batch sur le client et non pas parce que le contenu du script c'est correctement exécuté ! Si le fichier essai.txt n'existe pas cela devrait retourner un code erreur 1 donc que cela a échoué ce qui n'est pas le cas.
Quelqu'un d'entre vous saurait si c'est possible qu'un batch revoie un code erreur si les actions du script se sont bien déroulées ?
Cordialement MERCKEL Matthieu
Lorsqu'on exécute une commande avec "run", si la commande renvoie autre chose que le code de retour 0, une erreur ("exception") est déclenchée et l'installation est en status ERROR Si on stipule une liste au paramètre "accept_returncodes" (exemple [0,1]) alors run renverra une exception si le code de retour n'est pas dans la liste accept_returncodes
Dans votre cas, vous renvoyez 0 ou 1 et vous acceptez 0 et 1 comme code de retour "valides", c'est à dire n'étant pas des erreurs. Donc l'installation renvoie OK. C'est le comportement normal.
Le 31/05/2016 à 09:33, Service Info IUTLPS a écrit :
Bonjour
J’essaie d'obtenir le code erreur en sortie d'un batch pour le remonter à la console WAPT.
Je pars d'un modèle (template) vide où j'ai ajouté mon script et modifié le setup.py.
*Voici le contenu du fichier bat de test*
@ECHO OFF REM On teste si un fichier quelconque existe. IF EXIST "C:\essai.txt" ( REM Permet la sortie du script avec un code erreur. REM Ici, si le fichier existe on sort avec le code 0. exit /b 0 ) ELSE ( REM Sinon le code 1. exit /b 1 )
*Ci-dessous partie du setup.py que j'ai modifié en stipulant les codes retour.*
def install(): run("Batch.bat",accept_returncodes=[0,1])
En fait, j'ai l'impression que la console dit que l'installation est OK juste car il a exécuté le batch sur le client et non pas parce que le contenu du script c'est correctement exécuté ! Si le fichier essai.txt n'existe pas cela devrait retourner un code erreur 1 donc que cela a échoué ce qui n'est pas le cas.
Quelqu'un d'entre vous saurait si c'est possible qu'un batch revoie un code erreur si les actions du script se sont bien déroulées ?
Cordialement MERCKEL Matthieu