我试图进入Windows批处理文件和编程一般,我搞乱了我在网上发现的一个例子并制作了一个批处理文件,创建了另一个批处理文件(为了学习)
但我现在想要在命令提示符下输入,我有一个粗略的解决方案来制作批处理文件,然后创建另一个批处理文件并使用orignal .bat启动该文件(不用担心,代码在下面,有意义。)
基本上如果你输入1,我想在批处理中做一些事情,我知道我需要先做一个if,但是它试图让我在命令行输入的文字正在努力...任何帮助都会很棒!
@echo off
if exist CommandTest.bat (
echo File already exists...
pause
) else (
echo CommandTest.bat does not exist. Creating the file...
timeout /t 3 /NOBREAK>nul
echo Please wait while your file loads...
echo @echo off >CommandTest.bat
echo color 0a >>CommandTest.bat
echo echo Line number 1 >>CommandTest.bat
echo timeout /t 3 /NOBREAK>nul >>CommandTest.bat
echo echo Line number 2 >>CommandTest.bat
echo timeout /t 3 /NOBREAK>nul >>CommandTest.bat
echo echo Line number 3 >>CommandTest.bat
echo timeout /t 3 /NOBREAK>nul >>CommandTest.bat
echo echo Line number 4 >>CommandTest.bat
echo timeout /t 3 /NOBREAK>nul >>CommandTest.bat
timeout /t 2 /NOBREAK>nul
start CommandTest.bat
timeout /t 5 /NOBREAK>nul
)
我基本上试图将其重新设计为用户互动...
答案 0 :(得分:1)
根据您的评论,choice
是您的正确选择:
@echo off
echo 1 - do something
echo 2 - do something else
echo 3 - do nothing
choice /c 123 /m "take your choice "
if %errorlevel% == 1 echo let's do something
if %errorlevel% == 2 goto :other
if %errorlevel% == 3 echo let's do nothing
pause
goto :eof
:other
echo let's do something else
echo something else ...
pause