将特殊字符从一个批处理文件写入另一个
我正在尝试使用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"