如何在不按Enter的情况下以批处理脚本从控制台返回单个字符? [英] How can I return a single character from the console in a batch script without pressing enter?
本文介绍了如何在不按Enter的情况下以批处理脚本从控制台返回单个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从批处理脚本中读取/返回单个字符,而不必按Enter键,例如C/C ++中的getChar()
.我该怎么办?
I'd like to read/return a single character from a batch script without having to hit the enter key, like getChar()
in C/C++. How would I do this?
推荐答案
使用 CHOICE 命令
从此网站
@echo off
:menu
cls
echo.
echo A - Text for item A
echo B - Text for item B
echo C - End
echo.
choice /c:ABC > nul
if errorlevel 3 goto end
if errorlevel 2 goto B
if errorlevel 1 goto A
echo Error... choice not installed
goto end
:A
echo Commands for item A
pause
goto menu
:B
echo Commands for item B
pause
goto menu
:end
这篇关于如何在不按Enter的情况下以批处理脚本从控制台返回单个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文