【问题标题】:Batch file not echoing to text file correctly--Please give me a hand批处理文件未正确回显到文本文件 - 请帮帮我
【发布时间】:2013-09-27 19:05:10
【问题描述】:

我有一个从 0-100 计数的批处理文件,并将 1-100 回显到一个文本文件中。但前 9 个数字没有回显,它只是说回显已关闭。有人可以帮忙吗?

@echo off
:start
set /a count=%count%+1
echo %count%>>file.txt
if %count%==100 goto end
goto start
:end
pause

这是我正在使用的代码,文本输出如下。

ECHO is off.
10
11
12
13

如您所见,在跳过前 9 个之后,它一直计数到 100。

【问题讨论】:

    标签: batch-file


    【解决方案1】:

    echo %count%>>file.txt 之间添加一个空格。 2> 是重定向运算符。 Batch Redirect Operators。此外,如果 var 已经存在,请在 :start 之前添加 set count=

    您也可以使用For 循环来代替gotolabels。 - Batch For Loops

    @echo off
    :start
    set /a count=%count%+1
    echo %count% >>file.txt
    if %count%==100 goto end
    goto start
    :end
    pause
    

    【讨论】:

    【解决方案2】:

    最好的解决方案是参数的相反顺序:

    >>file.txt echo %count%
    

    【讨论】:

      猜你喜欢
      • 2011-03-03
      • 2011-03-09
      • 2017-11-03
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多