【问题标题】:Append something at the end of an echo command in batch [duplicate]在批处理命令的末尾附加一些内容[重复]
【发布时间】: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


【解决方案1】:

(ab)使用set /p 编写不带换行符:

@echo off
<nul set /p "=working...  "
timeout 3 >nul
echo done.

【讨论】:

    【解决方案2】:

    您可以将 -n 用于第一个命令。它不会为后回声添加换行符。

    echo -n "正在检查文件是否存在..."

    【讨论】:

    • batchecho没有任何开关。
    • 哦,我的错。我没注意到。谢谢。
    猜你喜欢
    • 2013-10-23
    • 2014-03-04
    • 2021-03-16
    • 2014-05-11
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    • 1970-01-01
    相关资源
    最近更新 更多