You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在.bat文件中正确转义字符串以实现无执行无引号原样输出

How to Output Special Characters in a Batch File Without Quotes or Command Execution

If you’ve tried using echo in a Windows batch file to print text containing < or > characters, you’ve likely hit two frustrating issues: either the command throws an error (since those characters are treated as redirection operators), or wrapping the text in quotes fixes the error but leaves unwanted quotes in the output.

The Fix: Use the ^ Escape Character

In Windows batch scripting, ^ works as the escape character—similar to \ in PHP—it tells the command interpreter to treat the following special character as plain text instead of parsing it as a command operator.

To get your desired output without quotes or unintended command execution, just prefix every < and > with ^. Here’s the working batch file code:

@echo off
rem Note all < and > are prefixed with a ^
echo Syntax: cmd.cmd -p ^<path^> -c ^<command^>
echo commands: mv
echo path: ./dirname ^<- no trailing slash

What This Outputs

When you run this batch file, your console will print exactly the content you want—clean, no quotes, no errors:

Syntax: cmd.cmd -p <path> -c <command>
commands: mv
path: ./dirname <- no trailing slash

内容的提问来源于stack exchange,提问作者Kim Steinhaug

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:24:48