我正在尝试创建一个批处理脚本,该脚本将创建另一个批处理脚本。 问题是其中一行没有添加,而是在遇到我想要创建的重定向时重定向到另一个文件。
@echo off
:: Pulls name variable from text file
set /p UN=<name.txt
::Begins creating sec.bat
echo @echo off >sec.bat
:: Creates a vbs script to say whatever the %UN% variable is previously set as to the user
echo echo set speech = wscript.CreateObject("SAPI.spVoice") >>temp.vbs >>sec.bat
echo set text=%UN%! >>sec.bat
:: This is where my error is happening. I want it to write the entire line
:: "echo speech.speak "%text%" >> temp.vbs" to sec.bat but it won't. It
:: instead writes the line in a file called temp.vbs
echo echo speech.speak "%text%" >> temp.vbs >>sec.bat
echo start temp.vbs >>sec.bat
echo timeout /t 1 >>nul >>sec.bat
echo del temp.vbs >>sec.bat
我已尝试将这些行单独添加到引号中,但这会导致它将引号写入bat文件,但它无法按预期工作。
答案 0 :(得分:0)
逃避>>
(^>^>
)就足够了:
@echo off
set /p UN=<name.txt
echo @echo off >sec.bat
echo echo set speech = wscript.CreateObject("SAPI.spVoice") ^>^>temp.vbs >>sec.bat
echo set text=%UN%! >>sec.bat
echo echo speech.speak "%text%" ^>^> temp.vbs >>sec.bat
echo start temp.vbs >>sec.bat
echo timeout /t 1 ^>^>nul >>sec.bat
echo del temp.vbs >>sec.bat