0

我有一个批处理文件,例如:test.bat,里面只有一个命令:

echo Hello

然后我运行它:

D:\cmd\test.bat

然后它输出结果:

 //output begin
                     -- This is a blank line, I don't want this
 D:\cmd\echo Hello   -- This is not what I want
 Hello               -- I only want to print this line
                     -- This is a blank line, I don't want neither.
 //output end

我只想打印批处理文件中运行的命令的输出,这里是echo命令。

但是,有两个空行,一个在结果的开头,另一个在结果的末尾。D:\cmd\echo Hello结果既不是我想要的。

我该怎么办?任何帮助都会很棒,在此先感谢。

4

1 回答 1

2

就放

@echo off

在批处理文件的第一行。这将防止在运行命令调用时输出它们(就像在命令前面加上 @ 一样),因此它消除了所有困扰您的行。

取自http://ss64.com/nt/echo.html

Type ECHO without parameters to display the current echo setting (ON or OFF).

In most batch files you will want ECHO OFF, turning it ON can be useful when 
debugging a problematic batch script.

In a batch file, the @ symbol is the same as ECHO OFF applied to the current line only.

Normally a command is executed and takes effect from the next line onwards, @ 
is a rare example of a command that takes effect immediately.
于 2013-07-31T04:49:36.443 回答