Wie kann man die Ausgabe des SET / P auffüllen?

364
user902300

Ich verwende dieses einfache Menü in cmd, in dem ich meine ECHOs mit dem TABSchlüssel aufgefüllt habe :

:MENU  ECHO select this by pressing 0 ECHO( ECHO select this by pressing 1 ECHO( SET /P ANSWER="press something:" 

Gibt es eine Möglichkeit, wie Sie die Ausgabe von auffüllen können SET /P ANSWER=?

Ich habe TABes bzw. SPACEes probiert, funktioniert aber nicht. es sieht aus wie das:

 select this by pressing 0  select this by pressing 1  press something:_ 

und ich möchte es so aussehen:

 select this by pressing 0  select this by pressing 1  press something:_ 
0

1 Antwort auf die Frage

1
JosefZ

Sie können einige Steuerzeichen verwenden, z. B. backspace ( U+0008) wie im folgenden Code-Snippet. Ein Tipp: Einzeltastendruck kann von der Tastatur erfasst werden choiceBefehl (siehe das Skript)

@ECHO OFF SETLOCAL EnableExtensions  rem get backspace character to BS variable for /F %%a in ('echo prompt $H ^| cmd') do set BS=%%a  :MENU ECHO( ECHO select this by pressing 0 ECHO( ECHO select that by pressing 1 ECHO( rem ↓ this character is deleted in output by backspace SET /P "ANSWER=X%BS% press something: " ECHO( echo "%ANSWER%" entered; another approach using CHOICE command: ECHO( CHOICE /C 01 /N /M "X%BS% Select [0] this or [1] that: " 

Ausgabe :

==> D:\bat\SU\1324661.bat  select this by pressing 0  select that by pressing 1  press something: s  "s" entered; another approach using CHOICE command:  Select [0] this or [1] that: 1  ==>