Syntax of echo incorrect in Batch file

时间:2018-02-05 12:59:07

标签: batch-file cmd echo

No idea whats going on here, so I hope someone can help.

I have a batch file that echos this:

echo +--------------------------------------------------------------------------+
echo | Booking System                                                           |
echo | By IT Department                                                         |
echo +--------------------------------------------------------------------------+
echo | IF YOU CAN SEE THIS, SOMETHING BROKE!                                    |
echo +--------------------------------------------------------------------------+
echo | IF YOU CAN NOT SEE THE BOOKING INTERFACE,PLEASE USE THE PHONE AND DIAL 0 |
echo +--------------------------------------------------------------------------+
echo |                                                                          |
echo +--------------------------------------------------------------------------+

But when I run the script, is gives me a Syntax error:

+--------------------------------------------------------------------------+
The syntax of the command is incorrect

2 个答案:

答案 0 :(得分:3)

问题在于:

echo | Booking System |

|是管道字符,它接受echo的输出并尝试将其连接到名为Booking的程序的标准输入(这可能不是{\ n}}使用参数System,然后将 程序的输出和管道输入到,没有任何内容。

因此出现错误,由最终管道引起的语法错误,无法运行程序。

你应该这样逃避管道字符:

echo ^| these will be treated as literal bar characters ^|

请参阅以下记录,该记录显示由未转义的管道(包括与您的案例相匹配的第二个)引起的错误和修复:

C:\users\Pax\Documents> echo | hello there
'hello' is not recognized as an internal or external command,
operable program or batch file.

C:\users\Pax\Documents> echo | hello there |
The syntax of the command is incorrect.

C:\users\Pax\Documents> echo ^| hello there ^|
| hello there |

答案 1 :(得分:-2)

您需要添加如下引号:

echo "+"---------------------------------------------------------"+"