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èmes avec le signe % [Batch]


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur de jeux vidéo
    Inscrit en
    Septembre 2020
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur de jeux vidéo

    Informations forums :
    Inscription : Septembre 2020
    Messages : 2
    Par défaut Problèmes avec le signe %
    Bonjour.
    Je cherche a créer un setup pour un logiciel en batch.
    Voici le code du logiciel :

    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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    @echo off
    set /a spacetexta=1
    :loop
    if %spacetexta%==1 (
    echo CMD by BoNUS
    )
    echo.
    set /a spacetexta=2
    echo Enter a command :
    set /p command=
    if %command%==text (
    echo Command %command% accepted.
    echo Enter the content of the text file :
    set /p text=
    goto :text
    )
    if %command%==msgbox (
    echo Command %command% accepted.
    echo Enter the content of the msgbox :
    set /p msgvar=
    goto :msg
    )
    if %command%==start (
    echo Command %command% accepted.
    echo Enter the application :
    set /p app=
    goto :start
    )
    if %command%==help (
    echo Command %command% accepted.
    goto :help
    )
    if %command%==calc (
    echo Command %command% accepted.
    echo Enter the operation :
    set /p calcvar=
    goto :calc
    )
    if %command%==clean (
    echo Command %command% accepted.
    goto :clean
    )
    if %command%==name (
    echo Command %command% accepted.
    echo Enter the new name of the cmd :
    set /p namevar=
    goto :name
    ) else (
    echo "%command%" is not a command.
    )
    goto :loop
     
    :text
    echo %text% > text.txt
    echo Operation finished.
    goto :loop
     
    :clean
    cls
    goto :loop
     
    :name
    title %namevar%
    goto :loop
     
    :msg
    echo msgbox "%msgvar%" > vbsmsgbox.vbs
    start vbsmsgbox.vbs
    goto :loop
     
    :start
    start %app%
    echo Operation finished.
    goto :loop
     
    :calc
    set /a op=%calcvar%
    echo The result is %op%.
    goto :loop
     
    :help
    start help.txt
    echo Help text file open.
    goto :loop

    Et voici celui du setup :

    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
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    @echo off
    echo @echo off > cmd.bat
    echo set /a spacetexta=1 >> cmd.bat
    echo :loop >> cmd.bat
    echo if %spacetexta%==1 ( >> cmd.bat
    echo echo CMD by BoNUS >> cmd.bat
    echo ) >> cmd.bat
    echo echo. >> cmd.bat
    echo set /a spacetexta=2 >> cmd.bat
    echo echo Enter a command : >> cmd.bat
    echo set /p command= >> cmd.bat
    echo if %command%==text ( >> cmd.bat
    echo echo Command %command% accepted. >> cmd.bat
    echo echo Enter the content of the text file : >> cmd.bat
    echo set /p text= >> cmd.bat
    echo goto :text >> cmd.bat
    echo ) >> cmd.bat
    echo if %command%==msgbox ( >> cmd.bat
    echo echo Command %command% accepted. >> cmd.bat
    echo echo Enter the content of the msgbox : >> cmd.bat
    echo set /p msgvar= >> cmd.bat
    echo goto :msg >> cmd.bat
    echo ) >> cmd.bat
    echo if %command%==start ( >> cmd.bat
    echo echo Command %command% accepted. >> cmd.bat
    echo echo Enter the application : >> cmd.bat
    echo set /p app= >> cmd.bat
    echo goto :start >> cmd.bat
    echo ) >> cmd.bat
    echo if %command%==help ( >> cmd.bat
    echo echo Command %command% accepted. >> cmd.bat
    echo goto :help >> cmd.bat
    echo ) >> cmd.bat
    echo if %command%==calc ( >> cmd.bat
    echo echo Command %command% accepted. >> cmd.bat
    echo echo Enter the operation : >> cmd.bat
    echo set /p calcvar= >> cmd.bat
    echo goto :calc >> cmd.bat
    echo ) >> cmd.bat
    echo if %command%==clean ( >> cmd.bat
    echo echo Command %command% accepted. >> cmd.bat
    echo goto :clean >> cmd.bat
    echo ) >> cmd.bat
    echo if %command%==name ( >> cmd.bat
    echo echo Command %command% accepted. >> cmd.bat
    echo echo Enter the new name of the cmd : >> cmd.bat
    echo set /p namevar= >> cmd.bat
    echo goto :name >> cmd.bat
    echo ) else ( >> cmd.bat
    echo echo "%command%" is not a command. >> cmd.bat
    echo ) >> cmd.bat
    echo goto :loop >> cmd.bat
    echo :text >> cmd.bat
    echo echo %text% > text.txt >> cmd.bat
    echo echo Operation finished. >> cmd.bat
    echo goto :loop >> cmd.bat
    echo :clean >> cmd.bat
    echo cls >> cmd.bat
    echo goto :loop >> cmd.bat
    echo :name >> cmd.bat
    echo title %namevar% >> cmd.bat
    echo goto :loop >> cmd.bat
    echo :msg >> cmd.bat
    echo echo msgbox "%msgvar%" > vbsmsgbox.vbs >> cmd.bat
    echo start vbsmsgbox.vbs >> cmd.bat
    echo goto :loop >> cmd.bat
    echo :start >> cmd.bat
    echo start %app% >> cmd.bat
    echo echo Operation finished. >> cmd.bat
    echo goto :loop >> cmd.bat
    echo :calc >> cmd.bat
    echo set /a op=%calcvar% >> cmd.bat
    echo echo The result is %op%. >> cmd.bat
    echo goto :loop >> cmd.bat
    echo :help >> cmd.bat
    echo start help.txt >> cmd.bat
    echo echo Help text file open. >> cmd.bat
    echo goto :loop >> cmd.bat

    L'exécution du setup me donne bien le fichier, mais les variables n'étant pas définies, j'ai, au lieu d'avoir if %command%==clean (, j'ai if ==clean (. Je cherche donc à désactiver l'utilisation du signe %, et qu'il soit enregistré comme un signe normal. Merci d'avance.

  2. #2
    Membre émérite
    Homme Profil pro
    Développeur .NET en devenir
    Inscrit en
    Août 2017
    Messages
    549
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    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 : 549
    Par défaut
    Bonjour,

    Pour éviter que certains caractères spéciaux soient interprétés, il faut les échapper.

    Voilà un tableau regroupant tous les caractères d'échappement : https://www.robvanderwoude.com/escapechars.php

    Dans ton cas il faut simplement doubler le signe %

  3. #3
    Candidat au Club
    Homme Profil pro
    Développeur de jeux vidéo
    Inscrit en
    Septembre 2020
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur de jeux vidéo

    Informations forums :
    Inscription : Septembre 2020
    Messages : 2
    Par défaut
    Citation Envoyé par barnabe0057 Voir le message
    Dans ton cas il faut simplement doubler le signe %
    Merci, ça marche parfaitement ! Sujet résolu !

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

Discussions similaires

  1. Problème avec le signe \
    Par lulu45 dans le forum Cpcdos
    Réponses: 8
    Dernier message: 04/03/2015, 16h24
  2. [PHP 5.3] Problème avec apostrophe et signe euro
    Par galak6 dans le forum Langage
    Réponses: 5
    Dernier message: 01/02/2012, 15h11
  3. [Beamer] Problème avec signes mathématiques
    Par Tex-Twil dans le forum Beamer
    Réponses: 2
    Dernier message: 07/09/2007, 18h00
  4. Problème avec le signe euro (€)
    Par linar009 dans le forum Administration système
    Réponses: 4
    Dernier message: 18/03/2007, 22h07
  5. [Tableaux] Problème avec le signe € et htmlentities
    Par berceker united dans le forum Langage
    Réponses: 6
    Dernier message: 28/12/2006, 15h57

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