将特殊字符从一个批处理文件写入另一个 [英] Writing special characters from one batch file to another

查看:118
本文介绍了将特殊字符从一个批处理文件写入另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用echo从另一个批处理文件写入一个批处理文件.但是,只有一行带有特殊字符,我无法弄清楚该怎么写.

I am trying to write one batch file from another, using echo. However, there is one line with special characters that I cannot work out how to write.

我有以下一行:

echo >nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" >> "c:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\OrchestrationCleanUp.bat"

但是写入目标文件的是:

But what gets written to the target file is:

 "C:\Windows\system32\cacls.exe" "C:\Windows\system32\config\system" 

应该是:

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

我尝试将其用双引号引起来.

I have tried putting it in double quotes.

我尝试过将^放在>

我尝试将其放在变量中并用双引号转义

I have tried putting it in a variable and escaping it with double quotes

我尝试将其放在变量中并使用!在每一端

I have tried putting it in a variable and using ! at each end

我尝试将其放在变量中,并在变量名的末尾使用:.

I have tried putting it in a variable and using a : at the end of the variable name.

推荐答案

特殊字符需要使用^进行转义,并且%符号必须加倍.试试这个:

The special characters need to be escaped with ^ and % signs have to be doubled. Try this:

回显后的(会立即停止某些前导字符的问题.

The ( directly after echo stops issues with some leading characters.

echo(^>nul 2^>^&1 "%%SYSTEMROOT%%\system32\cacls.exe" "%%SYSTEMROOT%%\system32\config\system" >> "c:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\OrchestrationCleanUp.bat"

这篇关于将特殊字符从一个批处理文件写入另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆