IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Problème de conditions dans un .bat [Batch]


Sujet :

Scripts/Batch

  1. #1
    Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Décembre 2018
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 48
    Points : 40
    Points
    40
    Par défaut Problème de conditions dans un .bat
    Bonjour à tous.
    Dernièrement j'ai eu l'aide de barnabe0057 pour un problème au niveau des choix multiples (et je l'en remercie encore).
    J'ai fait évoluer mon .bat pour y inclure plusieurs conditions.
    Toutes les conditions fonctionnent sauf 2. (lignes 43 et 44).
    Quand je fais les tests avec ces conditions, c'est toujours le script de la ligne 23 qui se lance alors que cela devrait être respectivement le script de la ligne 29 et celui de la ligne 33.
    Je ne vois pas du tout, où se situe mon erreur.
    Merci d'avance pour votre aide.
    Code batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    @echo off
    cd /d C:\Prepa_PC ||exit /b 1
    echo /!\ TESTQ /!\
    set /p VarQuestion1="Choisissez la marque du PC. Lenovo(L) ou Autre(A)"
    if "%VarQuestion1%"=="L" (goto :1)
    if "%VarQuestion1%"=="A" (goto :1)
    if "%VarQuestion1%" neq L (exit)
    if "%VarQuestion1%" neq A (exit)
    :1
    set "VarQuestion2="
    echo.
    set /p VarQuestion2="PC Pro(P) ou Perso (H) ?"
    if /i "%VarQuestion2%"=="P" (goto :9)
    if /i "%VarQuestion2%"=="H" (goto :9)
    :2
    set "VarQuestion3="
    echo.
    set /p VarQuestion3="32bits(32) ou 64bits(64) ?"
    if /i "%VarQuestion3%"=="32" (goto :10)
    if /i "%VarQuestion4%"=="64" (goto :11)
    echo.
    :3
    call C:\Prepa_PC\PRO\BATCH\ProL.bat
    :4
    call C:\Prepa_PC\PRO\BATCH\Pro.bat
    :5
    call C:\Prepa_PC\PERSO\BATCH\PersoLx32.bat
    :6
    call C:\Prepa_PC\PERSO\BATCH\PersoLx64.bat
    :7
    call C:\Prepa_PC\PERSO\BATCH\Persox32.bat
    :8
    call C:\Prepa_PC\PERSO\BATCH\Persox64.bat
    :9
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="P" (goto :3)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="P" (goto :4)
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" (goto :2)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" (goto :2)
    :10
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="32" (goto :5)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="32" (goto :7)
    :11
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="64" (goto :6)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="64" (goto :8)
    exit /b 0
    pause

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Bonjour,

    Un script .bat s'exécute de manière séquentielle, du haut vers le bas, à moins que tu ne rajoutes une de ces commandes GOTO, CALL, EXIT

    C'est donc tout à fait normal que ton script ne fonctionne pas de la manière attendue, pourtant je t'avais corrigé en plaçant des EXIT aux bons endroits.

    Je vais donc recommencer :

    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    @echo off
     
    cd /d C:\Prepa_PC ||exit /b 1
    echo /!\ TESTQ /!\
     
    set /p VarQuestion1="Choisissez la marque du PC. Lenovo(L) ou Autre(A)"
    if /i "%VarQuestion1%"=="L" (goto :1)
    if /i "%VarQuestion1%"=="A" (goto :1)
    exit
     
    :1
    set "VarQuestion2="
    echo.
    set /p VarQuestion2="PC Pro(P) ou Perso (H) ?"
    if /i "%VarQuestion2%"=="P" (goto :9)
    if /i "%VarQuestion2%"=="H" (goto :9)
    exit
     
    :2
    set "VarQuestion3="
    echo.
    set /p VarQuestion3="32bits(32) ou 64bits(64) ?"
    if "%VarQuestion3%"=="32" (goto :10)
    if "%VarQuestion4%"=="64" (goto :11)
    exit
     
    :3
    call C:\Prepa_PC\PRO\BATCH\ProL.bat
    exit
     
    :4
    call C:\Prepa_PC\PRO\BATCH\Pro.bat
    exit
     
    :5
    call C:\Prepa_PC\PERSO\BATCH\PersoLx32.bat
    exit
     
    :6
    call C:\Prepa_PC\PERSO\BATCH\PersoLx64.bat
    exit
     
    :7
    call C:\Prepa_PC\PERSO\BATCH\Persox32.bat
    exit
     
    :8
    call C:\Prepa_PC\PERSO\BATCH\Persox64.bat
    exit
     
    :9
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="P" (goto :3)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="P" (goto :4)
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" (goto :2)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" (goto :2)
    exit
     
    :10
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="32" (goto :5)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="32" (goto :7)
    exit
     
    :11
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="64" (goto :6)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="64" (goto :8)
    exit
    pause

  3. #3
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Ton script pourrait se résumer à ça :

    Code Batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    @echo off
    Setlocal EnableExtensions EnableDelayedExpansion
     
    cd /d C:\Prepa_PC || exit /b 1
     
    :debut
    set "marque="
    cls & echo /^^!\ TESTQ /^^!\
    set /p marque="Choisissez la marque du PC. Lenovo(L) ou Autre(A) "
    if /i "%marque%"=="L" (goto :1)
    if /i "%marque%"=="A" (goto :1)
    goto :debut
     
    :1
    set "type="
    echo.
    set /p type="PC Pro(P) ou Perso (H) ? "
    if /i "%type%"=="P" (goto :2)
    if /i "%type%"=="H" (goto :2)
    goto :debut
     
    :2
    set "arch="
    for /f "skip=1 tokens=1" %%A in ('wmic os get OSArchitecture ^| findstr /v "^$"') do set arch=%%A
     
    if /i "%marque%"=="L" (if /i "%type%"=="P" (call C:\Prepa_PC\PRO\BATCH\ProL.bat))
    if /i "%marque%"=="A" (if /i "%type%"=="P" (call C:\Prepa_PC\PRO\BATCH\Pro.bat))
    if /i "%marque%"=="L" (if /i "%type%"=="H" (call C:\Prepa_PC\PERSO\BATCH\PersoLx!arch!.bat))
    if /i "%marque%"=="A" (if /i "%type%"=="H" (call C:\Prepa_PC\PERSO\BATCH\Persox!arch!.bat))
     
    pause
    exit

  4. #4
    Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Décembre 2018
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 48
    Points : 40
    Points
    40
    Par défaut
    Bonjour barnabe0057.
    Tout d'abord toutes mes excuses pour le dérangement.
    Effectivement, je n'avais pas bien compris la fonctionnalité du EXIT.
    Je viens de refaire un test, et maintenant, un autre problème se pose.
    Quand je choisis les conditions citées plus haut, les .bat PersoLx64.bat et Persox64.bat ne se lancent pas.
    La fenêtre CMD se ferme.
    J'ai vérifié le chemin pour la fonction CALL mais ça ne vient pas de là. Une idée ?
    Par ailleurs, j'ai testé ton script : on est sur un autre niveau, et il faudra que je me penche plus sérieusement là dessus.
    Merci pour ton aide.

  5. #5
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Tu ne me déranges pas du tout, poste ton code si tu veux de l'aide.

  6. #6
    Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Décembre 2018
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 48
    Points : 40
    Points
    40
    Par défaut
    barnabe0057,

    J'ai repris mon code que tu as corrigé en fait.
    Code batch : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    @echo off
     
    cd /d C:\Prepa_PC ||exit /b 1
    echo /!\ TESTQ /!\
     
    set /p VarQuestion1="Choisissez la marque du PC. Lenovo(L) ou Autre(A)"
    if /i "%VarQuestion1%"=="L" (goto :1)
    if /i "%VarQuestion1%"=="A" (goto :1)
    exit
     
    :1
    set "VarQuestion2="
    echo.
    set /p VarQuestion2="PC Pro(P) ou Perso (H) ?"
    if /i "%VarQuestion2%"=="P" (goto :9)
    if /i "%VarQuestion2%"=="H" (goto :9)
    exit
     
    :2
    set "VarQuestion3="
    echo.
    set /p VarQuestion3="32bits(32) ou 64bits(64) ?"
    if "%VarQuestion3%"=="32" (goto :10)
    if "%VarQuestion4%"=="64" (goto :11)
    exit
     
    :3
    call C:\Prepa_PC\PRO\BATCH\ProL.bat
    exit
     
    :4
    call C:\Prepa_PC\PRO\BATCH\Pro.bat
    exit
     
    :5
    call C:\Prepa_PC\PERSO\BATCH\PersoLx32.bat
    exit
     
    :6
    call C:\Prepa_PC\PERSO\BATCH\PersoLx64.bat
    exit
     
    :7
    call C:\Prepa_PC\PERSO\BATCH\Persox32.bat
    exit
     
    :8
    call C:\Prepa_PC\PERSO\BATCH\Persox64.bat
    exit
     
    :9
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="P" (goto :3)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="P" (goto :4)
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" (goto :2)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" (goto :2)
    exit
     
    :10
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="32" (goto :5)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="32" (goto :7)
    exit
     
    :11
    if /i "%VarQuestion1%"=="L" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="64" (goto :6)
    if /i "%VarQuestion1%"=="A" if "%VarQuestion2%"=="H" if "%VarQuestion3%"=="64" (goto :8)
    exit
    pause

  7. #7
    Membre éprouvé
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    546
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur .NET en devenir
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2017
    Messages : 546
    Points : 1 084
    Points
    1 084
    Par défaut
    Tu as fait une erreur en nommant ta variable %VarQuestion4% au lieu de %VarQuestion3%.

  8. #8
    Membre du Club
    Homme Profil pro
    Technicien réseau
    Inscrit en
    Décembre 2018
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France, Pas de Calais (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Technicien réseau
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Décembre 2018
    Messages : 48
    Points : 40
    Points
    40
    Par défaut
    Ah ouai bien vu!
    Je suis complètement passé à côté!
    Je viens de corriger et tout roule!
    Merci encore pour ton aide!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [MySQL] Problème de condition dans le SELECT
    Par nicocaine dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 15/06/2007, 08h20
  2. problème de connect dans un .bat sous winXP
    Par sher56 dans le forum Connexion aux bases de données
    Réponses: 3
    Dernier message: 28/06/2006, 15h19
  3. problème de condition dans une macro
    Par Skizo dans le forum Access
    Réponses: 3
    Dernier message: 15/05/2006, 11h22
  4. [débutant] problème de condition dans une requete
    Par banker dans le forum Access
    Réponses: 5
    Dernier message: 22/03/2006, 13h52
  5. Réponses: 6
    Dernier message: 17/08/2005, 12h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo