batch-file - 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
解决方案
看起来你需要一个暂停命令。您的代码正在正确执行,但在您看到结果之前没有什么可以阻止代码退出。
@Echo off
Echo This message will not be displayed.
cls
Echo This message will be displayed.
pause
exit
在退出之前添加暂停将显示您的结果,直到按下按钮。
推荐阅读
- javascript - 如何在 svelte 项目中配置 sass 和 ESLint?
- java - 无法从其他类读取 Int
- c++ - C++ 中的二进制字面量
- mono - 如何将我的 ReactiveSecurityContextHolder 角色传递给 mono webclient 休息调用?
- point-cloud-library - PCL 重构翻转对象的点云
- python - 在 Discord.py 中创建角色时如何单独显示角色?
- docker - 更新后容器未重启,docker-compose.yml 中始终重启
- tensorflow - 为什么 TensorFlow XLA 需要许多新的 xla op 内核?
- tikv - 2 个不同的 TiKv 集群之间如何复制数据?
- php - 如何连接到 freewebhostingarea 上的数据库?