【发布时间】:2019-11-09 21:04:08
【问题描述】:
我想在已经执行的回显命令后面附加一些额外的文本。例如,“完成”或“失败”取决于事情是否顺利。
我正在尝试创建一个批处理文件来检查文件是否存在,然后继续下一步。我承认我不擅长批处理,我目前的解决方案是,使用 goto 语句,打印一个新行,无论它是否顺利。
目前的解决方案:
@echo off
cls
echo Checking if the file is present...
if exist "file" goto :Next
color 4
echo File not found!
pause
exit
:Next
color a
echo Done.
:: Rest of the script continues here.
我正在尝试做的事情:
@echo off
cls
echo Checking if the file is present...
if exist "file" goto :Next
:: Here it should append "File not found!" at the end of the previous echo
pause
exit
:Next
:: Here it should append "Done." at the end of the previous echo
:: Rest of the script continues here.
简单来说,预期的结果是允许在我之前通过 echo 输出的一行末尾附加一些内容,最好是颜色(这里我使用红色表示失败,绿色表示成功)。这可能吗?如果是这样,我将如何去做?
请注意,可能有更好的方法来布置我的脚本,如前所述,我不擅长批处理。
任何帮助将不胜感激!
【问题讨论】:
-
您似乎没有尝试执行您解释过的任务。如果我们没有看到您的代码,我们将无法帮助您修复它。这不是免费的代码编写服务,请在 editing your question 之前阅读 tour 并阅读 How to Ask 以将其带到 StackOverflow 的主题。
标签: batch-file append echo