首页 > 解决方案 > Why does batch script keep exiting after set /P user prompt?

问题描述

@echo off
cls

echo Hello, there! Today is
date /t
echo and the current time is 
time /t

echo I'm so glad to meet you. My name is Hal 10000.
set /p name=What's your name?

cls

echo Well hello, %name%
echo Hey, %name%, & set /p "age"="how old are you in years?"
echo Well that's just great! I'm actually 115 today.
echo I look pretty good, huh!?
echo Well, gotta go, by!

exit

标签: batch-file

解决方案


看起来你需要一个暂停命令。您的代码正在正确执行,但在您看到结果之前没有什么可以阻止代码退出。

@Echo off
Echo This message will not be displayed.
cls
Echo This message will be displayed.
pause
exit

在退出之前添加暂停将显示您的结果,直到按下按钮。


推荐阅读